Commit 9739123f6f4dc20199b0202f8598c3c4ec9c75e2

Authored by Peng Fan
Committed by guoyin.chen
1 parent 1a07d4585b

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)

Showing 1 changed file with 7 additions and 2 deletions Side-by-side Diff

... ... @@ -2470,11 +2470,16 @@
2470 2470 }
2471 2471 argc = ++child->argc;
2472 2472 child->argv = realloc(child->argv, (argc+1)*sizeof(*child->argv));
2473   - if (child->argv == NULL) return 1;
  2473 + if (child->argv == NULL) {
  2474 + free(str);
  2475 + return 1;
  2476 + }
2474 2477 child->argv_nonnull = realloc(child->argv_nonnull,
2475 2478 (argc+1)*sizeof(*child->argv_nonnull));
2476   - if (child->argv_nonnull == NULL)
  2479 + if (child->argv_nonnull == NULL) {
  2480 + free(str);
2477 2481 return 1;
  2482 + }
2478 2483 child->argv[argc-1]=str;
2479 2484 child->argv_nonnull[argc-1] = dest->nonnull;
2480 2485 child->argv[argc]=NULL;