Re: [U-Boot] [PATCH 1/1] common: cli: avoid memory leak

2016-01-04 Thread Tom Rini
On Mon, Dec 28, 2015 at 01:12:21PM +0800, Peng Fan wrote:
> Hi Simon,
> On Sun, Dec 27, 2015 at 09:22:01PM -0700, Simon Glass wrote:
> >Hi Peng,
> >
> >On 22 December 2015 at 02:14, Peng Fan  wrote:
> >> From: Peng Fan 
> >>
> >> Whether CONFIG_SYS_HUSH_PARSER is defined or not, should always
> >> check to free 'buff' to avoid memory leak.
> >
> >Are you sure? I believe need_buff is only true if the simple parser is
> >being used.
> 
> If CONFIG_SYS_HUSH_PARSER is defined and len is not -1, need_buff is 1, then
> will malloc buffer and assign return value to buff.
> But we only free buff, when CONFIG_SYS_HUSH_PARSER is not defined and 
> need_buff is 1.
> So I think this may leaks memory.

Yes, this may happen.  The code itself however should be rearranged (not
in this patch) to be clear on what we're doing here and if len will
really should ever be -1 (or always be -1?) or not.

-- 
Tom


signature.asc
Description: Digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 1/1] common: cli: avoid memory leak

2015-12-27 Thread Peng Fan
Hi Simon,
On Sun, Dec 27, 2015 at 09:22:01PM -0700, Simon Glass wrote:
>Hi Peng,
>
>On 22 December 2015 at 02:14, Peng Fan  wrote:
>> From: Peng Fan 
>>
>> Whether CONFIG_SYS_HUSH_PARSER is defined or not, should always
>> check to free 'buff' to avoid memory leak.
>
>Are you sure? I believe need_buff is only true if the simple parser is
>being used.

If CONFIG_SYS_HUSH_PARSER is defined and len is not -1, need_buff is 1, then
will malloc buffer and assign return value to buff.
But we only free buff, when CONFIG_SYS_HUSH_PARSER is not defined and need_buff 
is 1.
So I think this may leaks memory.

I am not familar with HUSH PARSER internal. If it can handle the upper case that
I described, then no need this patch.

Regards,
Peng.

>
>>
>> Signed-off-by: Peng Fan 
>> Cc: Tom Rini 
>> Cc: Masahiro Yamada 
>> Cc: Simon Glass 
>> ---
>>  common/cli.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/common/cli.c b/common/cli.c
>> index fbcd339..119d282 100644
>> --- a/common/cli.c
>> +++ b/common/cli.c
>> @@ -103,9 +103,9 @@ int run_command_list(const char *cmd, int len, int flag)
>>  * is pretty rare.
>>  */
>> rcode = cli_simple_run_command_list(buff, flag);
>> +#endif
>> if (need_buff)
>> free(buff);
>> -#endif
>>
>> return rcode;
>>  }
>> --
>> 2.6.2
>>
>
>Regards,
>Simon
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


Re: [U-Boot] [PATCH 1/1] common: cli: avoid memory leak

2015-12-27 Thread Simon Glass
Hi Peng,

On 22 December 2015 at 02:14, Peng Fan  wrote:
> From: Peng Fan 
>
> Whether CONFIG_SYS_HUSH_PARSER is defined or not, should always
> check to free 'buff' to avoid memory leak.

Are you sure? I believe need_buff is only true if the simple parser is
being used.

>
> Signed-off-by: Peng Fan 
> Cc: Tom Rini 
> Cc: Masahiro Yamada 
> Cc: Simon Glass 
> ---
>  common/cli.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/common/cli.c b/common/cli.c
> index fbcd339..119d282 100644
> --- a/common/cli.c
> +++ b/common/cli.c
> @@ -103,9 +103,9 @@ int run_command_list(const char *cmd, int len, int flag)
>  * is pretty rare.
>  */
> rcode = cli_simple_run_command_list(buff, flag);
> +#endif
> if (need_buff)
> free(buff);
> -#endif
>
> return rcode;
>  }
> --
> 2.6.2
>

Regards,
Simon
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot