From: Peng Fan <b51431@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] common: cli_hush: avoid memory leak
Date: Fri, 27 Nov 2015 10:04:17 +0800 [thread overview]
Message-ID: <20151127020414.GA22834@shlinux2> (raw)
In-Reply-To: <CAPnjgZ3Lw7KGsWkHKY_jH=e41cCdU9qBbkH1LK3Bh2wBytEWsg@mail.gmail.com>
Hi Simon,
On Thu, Nov 26, 2015 at 09:49:38AM -0800, Simon Glass wrote:
>Hi Peng,
>
>On 25 November 2015 at 02:16, Peng Fan <Peng.Fan@freescale.com> wrote:
>> Need to free memory avoid memory leak, when error.
>>
>> Signed-off-by: Peng Fan <Peng.Fan@freescale.com>
>> Cc: Simon Glass <sjg@chromium.org>
>> Cc: Tom Rini <trini@konsulko.com>
>> ---
>> common/cli_hush.c | 4 +++-
>> 1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/common/cli_hush.c b/common/cli_hush.c
>> index f075459..ab85225 100644
>> --- a/common/cli_hush.c
>> +++ b/common/cli_hush.c
>> @@ -2474,8 +2474,10 @@ static int done_word(o_string *dest, struct p_context *ctx)
>> if (child->argv == NULL) 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
>>
>>
>
>Reviewed-by: Simon Glass <sjg@chromium.org>
>
>It looks like there is another memory leak at the 'return 1' immediately above.
My coverity check tool does not report this (:-, but seems this is true memory
leak if child->argv is NULL. Thanks for pointing this out. I'll fix this in V2.
Thanks,
Peng.
>
>Regards,
>Simon
--
prev parent reply other threads:[~2015-11-27 2:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-25 9:16 [U-Boot] [PATCH] common: cli_hush: avoid memory leak Peng Fan
2015-11-25 9:16 ` [U-Boot] [PATCH] common: mmc: unsigned char compared against 0 Peng Fan
2015-11-27 2:51 ` Simon Glass
2015-11-27 4:58 ` Peng Fan
2015-12-06 22:06 ` [U-Boot] " Tom Rini
2015-11-26 17:49 ` [U-Boot] [PATCH] common: cli_hush: avoid memory leak Simon Glass
2015-11-27 2:04 ` Peng Fan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20151127020414.GA22834@shlinux2 \
--to=b51431@freescale.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox