From: Eric Sandeen Date: Fri, 16 Sep 2011 20:49:29 +0000 (-0500) Subject: subst: Fix free of uninit pointers X-Git-Tag: v1.42-WIP-0925~26 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=d5c1d82ed8812a036846267a1720faec223c0ba0;p=tools%2Fe2fsprogs.git subst: Fix free of uninit pointers in add_subst(), if the malloc of ent->name fails, we goto fail; which will free ent->name (which is null, so OK) but also free ent->value (which is uninitialized). There is no case where we must free ent->value on an error (it is allocated last, and if it fails it of course doesn't need to be freed) so just remove it. Also "retval" is only assigned once to the constant ENOMEM, so we can just return that explicitly in the failure case. Signed-off-by: Eric Saneeen Signed-off-by: Eric Sandeen Signed-off-by: Theodore Ts'o --- diff --git a/util/subst.c b/util/subst.c index b55f54b..8544b6d 100644 --- a/util/subst.c +++ b/util/subst.c @@ -35,9 +35,7 @@ struct subst_entry *subst_table = 0; static int add_subst(char *name, char *value) { struct subst_entry *ent = 0; - int retval; - retval = ENOMEM; ent = (struct subst_entry *) malloc(sizeof(struct subst_entry)); if (!ent) goto fail; @@ -55,10 +53,9 @@ static int add_subst(char *name, char *value) fail: if (ent) { free(ent->name); - free(ent->value); free(ent); } - return retval; + return ENOMEM; } static struct subst_entry *fetch_subst_entry(char *name)