Fix bad free order in tlcl_generator.c.
Fix suggested by the OpenSUSE friends:
https://build.opensuse.org/package/view_file?expand=1&file=fix-tlcl-generator.patch&package=vboot&project=devel%3AFactory%3AARM%3AContrib%3AChromebook
for this bug:
http://paste.opensuse.org/86254908
BUG=chromium-os:37707
TEST=emerge-daisy vboot_reference
BRANCH=none
Change-Id: I61c116152fab7b997a84f44da89c93b89659e852
Reviewed-on: https://gerrit.chromium.org/gerrit/40902
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Tested-by: Luigi Semenzato <semenzato@chromium.org>
Commit-Queue: Luigi Semenzato <semenzato@chromium.org>
diff --git a/utility/tlcl_generator.c b/utility/tlcl_generator.c
index 659a05d..882562b 100644
--- a/utility/tlcl_generator.c
+++ b/utility/tlcl_generator.c
@@ -54,7 +54,7 @@
* added at increasing offsets.
*/
static void AddVisibleField(Command* cmd, const char* name, int offset) {
- Field* fld = (Field*) malloc(sizeof(Field));
+ Field* fld = (Field*) calloc(1, sizeof(Field));
if (cmd->fields != NULL) {
assert(offset > fn->offset);
}
@@ -70,7 +70,7 @@
*/
static void AddInitializedField(Command* cmd, int offset,
int size, uint32_t value) {
- Field* fld = (Field*) malloc(sizeof(Field));
+ Field* fld = (Field*) calloc(1, sizeof(Field));
fld->next = cmd->fields;
cmd->fields = fld;
fld->name = NULL;
@@ -83,7 +83,7 @@
/* Create a structure representing a TPM command datagram.
*/
Command* newCommand(TPM_COMMAND_CODE code, int size) {
- Command* cmd = (Command*) malloc(sizeof(Command));
+ Command* cmd = (Command*) calloc(1, sizeof(Command));
cmd->size = size;
AddInitializedField(cmd, 0, sizeof(TPM_TAG), TPM_TAG_RQU_COMMAND);
AddInitializedField(cmd, sizeof(TPM_TAG), sizeof(uint32_t), size);
@@ -523,8 +523,8 @@
static void FreeCommands(Command* cmd) {
if (cmd != NULL) {
Command* next_command = cmd->next;
- free(cmd);
FreeFields(cmd->fields);
+ free(cmd);
FreeCommands(next_command);
}
}