summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorEric Sandeen <sandeen@redhat.com>2011-09-16 15:49:29 -0500
committerTheodore Ts'o <tytso@mit.edu>2011-09-16 18:43:05 -0400
commitd5c1d82ed8812a036846267a1720faec223c0ba0 (patch)
tree3bb6e78a8a7d9cde6e18094860d099d0ae14fde0 /util
parent624e8ebe3058bad9af6e719b7f9e7afab7d3fe30 (diff)
downloade2fsprogs-d5c1d82ed8812a036846267a1720faec223c0ba0.tar.gz
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 <sandeen@redhat.com> Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'util')
-rw-r--r--util/subst.c5
1 files changed, 1 insertions, 4 deletions
diff --git a/util/subst.c b/util/subst.c
index b55f54bc..8544b6da 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)