]> git.sur5r.net Git - u-boot/commitdiff
common: cli_hush: avoid memory leak
authorPeng Fan <Peng.Fan@freescale.com>
Fri, 27 Nov 2015 02:12:02 +0000 (10:12 +0800)
committerTom Rini <trini@konsulko.com>
Sat, 5 Dec 2015 23:22:28 +0000 (18:22 -0500)
Need to free memory avoid memory leak, when error.

Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Cc: Simon Glass <sjg@chromium.org>
Cc: Tom Rini <trini@konsulko.com>
common/cli_hush.c

index f075459911e02f714d39d1f45020fabc52991962..7f69c062a7ae04151f6d9a36bb424920a5ebd7dd 100644 (file)
@@ -2471,11 +2471,16 @@ static int done_word(o_string *dest, struct p_context *ctx)
                }
                argc = ++child->argc;
                child->argv = realloc(child->argv, (argc+1)*sizeof(*child->argv));
-               if (child->argv == NULL) return 1;
+               if (child->argv == NULL) {
+                       free(str);
+                       return 1;
+               }
                child->argv_nonnull = realloc(child->argv_nonnull,
                                        (argc+1)*sizeof(*child->argv_nonnull));
-               if (child->argv_nonnull == NULL)
+               if (child->argv_nonnull == NULL) {
+                       free(str);
                        return 1;
+               }
                child->argv[argc-1]=str;
                child->argv_nonnull[argc-1] = dest->nonnull;
                child->argv[argc]=NULL;