From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peng Fan Date: Fri, 27 Nov 2015 10:12:02 +0800 Subject: [U-Boot] [PATCH V2] common: cli_hush: avoid memory leak Message-ID: <1448590322-14135-1-git-send-email-Peng.Fan@freescale.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Need to free memory avoid memory leak, when error. Signed-off-by: Peng Fan Reviewed-by: Simon Glass Cc: Simon Glass Cc: Tom Rini --- Changes V2: Take Simon's comments, fix another memory leak when child->argv is NULL. Add Simon's review tag. common/cli_hush.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/common/cli_hush.c b/common/cli_hush.c index f075459..7f69c06 100644 --- a/common/cli_hush.c +++ b/common/cli_hush.c @@ -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; -- 2.6.2