diff options
author | Tom Rini <trini@konsulko.com> | 2017-09-26 19:43:12 +0300 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2017-10-06 18:28:20 +0300 |
commit | d91062c41e1542ffb2f8590cce75fb5a2b397fdc (patch) | |
tree | 380174d01bce580150ab163ca1b73fd32eb87443 /test/overlay/cmd_ut_overlay.c | |
parent | 18030d04d25d7c08d3deff85881772a520d84d49 (diff) | |
download | u-boot-d91062c41e1542ffb2f8590cce75fb5a2b397fdc.tar.xz |
test/overlay: Fix various malloc/free leaks
With the overlay tests now being built in sandbox Coverity has found a
number of issues in the tests. In short, if malloc ever failed we would
leak the previous mallocs, so we need to do the usual goto pattern to
free each in turn. Finally, we always looked at the free()d location to
see how many tests had failed for the return code.
Reported-by: Coverity (CID: 167224, 167227, 167230, 167236)
Signed-off-by: Tom Rini <trini@konsulko.com>
Diffstat (limited to 'test/overlay/cmd_ut_overlay.c')
-rw-r--r-- | test/overlay/cmd_ut_overlay.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/test/overlay/cmd_ut_overlay.c b/test/overlay/cmd_ut_overlay.c index 24891ee829..c730a11f51 100644 --- a/test/overlay/cmd_ut_overlay.c +++ b/test/overlay/cmd_ut_overlay.c @@ -226,6 +226,7 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) void *fdt_overlay = &__dtb_test_fdt_overlay_begin; void *fdt_overlay_stacked = &__dtb_test_fdt_overlay_stacked_begin; void *fdt_base_copy, *fdt_overlay_copy, *fdt_overlay_stacked_copy; + int ret = -ENOMEM; uts = calloc(1, sizeof(*uts)); if (!uts) @@ -236,16 +237,16 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) fdt_base_copy = malloc(FDT_COPY_SIZE); if (!fdt_base_copy) - return -ENOMEM; + goto err1; uts->priv = fdt_base_copy; fdt_overlay_copy = malloc(FDT_COPY_SIZE); if (!fdt_overlay_copy) - return -ENOMEM; + goto err2; fdt_overlay_stacked_copy = malloc(FDT_COPY_SIZE); if (!fdt_overlay_stacked_copy) - return -ENOMEM; + goto err3; /* * Resize the FDT to 4k so that we have room to operate on @@ -293,11 +294,18 @@ int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } printf("Failures: %d\n", uts->fail_count); + if (!uts->fail_count) + ret = 0; + else + ret = CMD_RET_FAILURE; free(fdt_overlay_stacked_copy); +err3: free(fdt_overlay_copy); +err2: free(fdt_base_copy); +err1: free(uts); - return uts->fail_count ? CMD_RET_FAILURE : 0; + return ret; } |