Skip to contentSkip to conversation

common: cli_hush: avoid memory leak

PATCH New Peng Fan 3 participants 3 messages Nov 27, 2015 – Dec 6, 2015

lore
Share & tools
lore

Peng Fan

author
#0 lore raw

PATCH v2 1/1 common: cli_hush: avoid memory leak

Need to free memory avoid memory leak, when error.

---

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
index f075459..7f69c06 100644
@@ -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
#1 lore raw

PATCH v2 1/1 common: cli_hush: avoid memory leak

Quoted 6 lines · Peng Fan

Need to free memory avoid memory leak, when error.

Quoted 8 lines

---

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(-)

Looks good!

- Simon

#2 lore raw

PATCH v2 1/1 common: cli_hush: avoid memory leak

In reply to Peng Fan
Quoted 6 lines · Peng Fan

Need to free memory avoid memory leak, when error.

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>