lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Mon, 5 Sep 2022 19:22:00 +0800
From:   shangxiaojing <shangxiaojing@...wei.com>
To:     Jiri Olsa <olsajiri@...il.com>
CC:     <peterz@...radead.org>, <mingo@...hat.com>, <acme@...nel.org>,
        <mark.rutland@....com>, <alexander.shishkin@...ux.intel.com>,
        <namhyung@...nel.org>, <linux-perf-users@...r.kernel.org>,
        <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH 3/3] perf c2c: Prevent potential memory leak in
 c2c_he_zalloc


On 2022/9/5 18:19, Jiri Olsa wrote:
> On Sat, Sep 03, 2022 at 03:25:42PM +0800, Shang XiaoJing wrote:
>> Free allocated resources when zalloc is failed for members in c2c_he, to
>> prevent potential memory leak in c2c_he_zalloc.
>>
>> Signed-off-by: Shang XiaoJing <shangxiaojing@...wei.com>
>> ---
>>   tools/perf/builtin-c2c.c | 14 +++++++++++---
>>   1 file changed, 11 insertions(+), 3 deletions(-)
>>
>> diff --git a/tools/perf/builtin-c2c.c b/tools/perf/builtin-c2c.c
>> index 12f272811487..5530433eda80 100644
>> --- a/tools/perf/builtin-c2c.c
>> +++ b/tools/perf/builtin-c2c.c
>> @@ -146,15 +146,15 @@ static void *c2c_he_zalloc(size_t size)
>>   
>>   	c2c_he->cpuset = bitmap_zalloc(c2c.cpus_cnt);
>>   	if (!c2c_he->cpuset)
>> -		return NULL;
>> +		goto out_free_he;
>>   
>>   	c2c_he->nodeset = bitmap_zalloc(c2c.nodes_cnt);
>>   	if (!c2c_he->nodeset)
>> -		return NULL;
>> +		goto out_free_cpuset;
>>   
>>   	c2c_he->node_stats = zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_stats));
>>   	if (!c2c_he->node_stats)
>> -		return NULL;
>> +		goto out_free_nodeset;
>>   
>>   	init_stats(&c2c_he->cstats.lcl_hitm);
>>   	init_stats(&c2c_he->cstats.rmt_hitm);
>> @@ -163,6 +163,14 @@ static void *c2c_he_zalloc(size_t size)
>>   	init_stats(&c2c_he->cstats.load);
>>   
>>   	return &c2c_he->he;
> nit, given that c2c_he is zero allocated we could just have
> single error label that would free everything
>
> for the patchset:
>
> Acked-by: Jiri Olsa <jolsa@...nel.org>
>
> thanks,
> jirka

right, i'll be mindful of that in future.

this will be done in v2.

>> +
>> +out_free_nodeset:
>> +	free(c2c_he->nodeset);
>> +out_free_cpuset:
>> +	free(c2c_he->cpuset);
>> +out_free_he:
>> +	free(c2c_he);
>> +	return NULL;
>>   }
>>   
>>   static void c2c_he_free(void *he)
>> -- 
>> 2.17.1

Thanks,

Shang XiaoJing

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ