Re: [PATCH] perf tool: fix trivial memory leak while calling system_path()

From: liang xie
Date: Wed Sep 05 2012 - 10:09:00 EST


Hi Felipe,

Thanks for reviewing! yeh, the check could be removed safely .
For casting, it'll complain like this if removed:
cc1: warnings being treated as errors
util/help.c: In function ‘load_command_list’:
util/help.c:190: error: passing argument 1 of ‘free’ discards
qualifiers from pointer target type
/usr/include/stdlib.h:488: note: expected ‘void *’ but argument is of
type ‘const char *’
make: *** [util/help.o] Error 1

Best Regards,

On Wed, Sep 5, 2012 at 9:49 PM, Felipe Balbi <balbi@xxxxxx> wrote:
> Hi,
>
> On Wed, Sep 05, 2012 at 09:48:54PM +0800, liang xie wrote:
>> A trivial memory leak fix while calling system_path
>>
>> Signed-off-by: Liang Xie <xieliang@xxxxxxxxxx>
>> ---
>> tools/perf/util/exec_cmd.c | 6 ++++--
>> tools/perf/util/help.c | 1 +
>> 2 files changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/perf/util/exec_cmd.c b/tools/perf/util/exec_cmd.c
>> index 7adf4ad..790cc95 100644
>> --- a/tools/perf/util/exec_cmd.c
>> +++ b/tools/perf/util/exec_cmd.c
>> @@ -83,8 +83,8 @@ void setup_path(void)
>> {
>> const char *old_path = getenv("PATH");
>> struct strbuf new_path = STRBUF_INIT;
>> -
>> - add_path(&new_path, perf_exec_path());
>> + const char *exec_path = perf_exec_path();
>> + add_path(&new_path, exec_path);
>> add_path(&new_path, argv0_path);
>>
>> if (old_path)
>> @@ -95,6 +95,8 @@ void setup_path(void)
>> setenv("PATH", new_path.buf, 1);
>>
>> strbuf_release(&new_path);
>> + if (exec_path)
>
> free(NULL) is safe, the check isn't needed.
>
>> + free((void *)exec_path);
>
> this cast doesn't look necessary either.
>
> --
> balbi
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/