common: cli_hush: avoid memory leak
PATCH v2 1/1 common: cli_hush: avoid memory leak
Need to free memory avoid memory leak, when error.
Signed-off-by Peng Fan <[email protected]>
Reviewed-by Simon Glass <[email protected]>
Cc Simon Glass <[email protected]>
Cc Tom Rini <[email protected]>
---
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(-)
common/cli_hush.c +7 -2
@@ -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 ;
Signature · 1 line
2.6.2
PATCH v2 1/1 common: cli_hush: avoid memory leak
Quoted 6 lines · Peng Fan
Need to free memory avoid memory leak, when error.
Signed-off-by Peng Fan <[email protected]>Reviewed-by Simon Glass <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>
Quoted 8 lines
---
Changes V2:
Take Simon's comments, fix another memory leak whenchild->argvis NULL. Add Simon's review tag.common/cli_hush.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
Looks good!
- Simon
PATCH v2 1/1 common: cli_hush: avoid memory leak
In reply to Peng FanQuoted 6 lines · Peng Fan
Need to free memory avoid memory leak, when error.
Signed-off-by Peng Fan <[email protected]>Reviewed-by Simon Glass <[email protected]>Cc Simon Glass <[email protected]>Cc Tom Rini <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: Digital signature URL: <http://lists.denx.de/pipermail/u-boot/attachments/20151206/e0060ed1/attachment.sig>