summaryrefslogtreecommitdiff
path: root/common/cli_hush.c
diff options
context:
space:
mode:
authorPeng Fan <Peng.Fan@freescale.com>2015-11-27 10:12:02 +0800
committerfang hui <hui.fang@freescale.com>2016-03-16 13:48:12 +0800
commitdef93c4031b683b5b8caf85b7aedb13f7272bb97 (patch)
tree5a9ac11b224bdc5b32fd9b95553c4aeff6e7632d /common/cli_hush.c
parent4c46ddb62f28bbe84ab21df55eacbf321dcfaf65 (diff)
downloadu-boot-imx-def93c4031b683b5b8caf85b7aedb13f7272bb97.zip
u-boot-imx-def93c4031b683b5b8caf85b7aedb13f7272bb97.tar.gz
u-boot-imx-def93c4031b683b5b8caf85b7aedb13f7272bb97.tar.bz2
common: cli_hush: avoid memory leak
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> (cherry picked from commit c6bb23c819b5dcbc5c3491673f5e408c0b9c38b3)
Diffstat (limited to 'common/cli_hush.c')
-rw-r--r--common/cli_hush.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/common/cli_hush.c b/common/cli_hush.c
index 5d78463..5be7b0f 100644
--- a/common/cli_hush.c
+++ b/common/cli_hush.c
@@ -2470,11 +2470,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;