summaryrefslogtreecommitdiff
path: root/util/cbfstool/flashmap/fmap.c
diff options
context:
space:
mode:
authorJacob Garber <jgarber1@ualberta.ca>2019-07-18 15:57:45 -0600
committerMartin Roth <martinroth@google.com>2019-07-21 18:54:43 +0000
commit3a82e9b8a32b80edc5f21bb7f4dae4dcb1d047b2 (patch)
tree14a2b12cdb21ee7893c6d00b07879bf54df68a1d /util/cbfstool/flashmap/fmap.c
parentb3042ed234ee38aed217b652e868f5dc0711c194 (diff)
util/cbfstool/flashmap: Fix memory leaks on failure
Fix several memory leaks on failed printing or tests. These don't matter much, but it keeps Coverity happy. Change-Id: Ie750acb50ae1590c3aea533338a8827c03459c1a Signed-off-by: Jacob Garber <jgarber1@ualberta.ca> Found-by: Coverity CID 130245{1,2,3} Reviewed-on: https://review.coreboot.org/c/coreboot/+/34412 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: HAOUAS Elyes <ehaouas@noos.fr>
Diffstat (limited to 'util/cbfstool/flashmap/fmap.c')
-rw-r--r--util/cbfstool/flashmap/fmap.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/util/cbfstool/flashmap/fmap.c b/util/cbfstool/flashmap/fmap.c
index 06f179f1f9..6255fc5633 100644
--- a/util/cbfstool/flashmap/fmap.c
+++ b/util/cbfstool/flashmap/fmap.c
@@ -236,8 +236,11 @@ int fmap_print(const struct fmap *fmap)
/* Print descriptive strings for flags rather than the field */
flags = fmap->areas[i].flags;
- if ((str = fmap_flags_to_string(flags)) == NULL)
+ str = fmap_flags_to_string(flags);
+ if (str == NULL) {
+ kv_pair_free(pair);
return -1;
+ }
kv_pair_fmt(pair, "area_flags", "%s", str);
free(str);
@@ -509,7 +512,8 @@ fmap_find_area_test_exit:
static int fmap_flags_to_string_test(void)
{
- char *str, *my_str;
+ char *str = NULL;
+ char *my_str = NULL;
unsigned int i;
uint16_t flags;
@@ -555,11 +559,11 @@ static int fmap_flags_to_string_test(void)
printf("FAILURE: bad result from fmap_flags_to_string\n");
goto fmap_flags_to_string_test_exit;
}
- free(my_str);
- free(str);
status = pass;
fmap_flags_to_string_test_exit:
+ free(str);
+ free(my_str);
return status;
}