linux-perf-users.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: shangxiaojing <shangxiaojing@huawei.com>
To: Jiri Olsa <olsajiri@gmail.com>
Cc: <peterz@infradead.org>, <mingo@redhat.com>, <acme@kernel.org>,
	<mark.rutland@arm.com>, <alexander.shishkin@linux.intel.com>,
	<namhyung@kernel.org>, <linux-perf-users@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 3/3] perf c2c: Prevent potential memory leak in c2c_he_zalloc
Date: Mon, 5 Sep 2022 19:22:00 +0800	[thread overview]
Message-ID: <7bb62639-a94e-907c-7110-aad45dda4db4@huawei.com> (raw)
In-Reply-To: <YxXNHtXoOeZG9Bzb@krava>


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@huawei.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@kernel.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


      reply	other threads:[~2022-09-05 11:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-03  7:25 [PATCH 0/3] perf: Clean up and fix potential mem leak Shang XiaoJing
2022-09-03  7:25 ` [PATCH 1/3] perf clean: Add same_cmd_with_prefix helper Shang XiaoJing
2022-09-03  7:25 ` [PATCH 2/3] perf c2c: Add helpers to get counts of loads or stores Shang XiaoJing
2022-09-03  7:25 ` [PATCH 3/3] perf c2c: Prevent potential memory leak in c2c_he_zalloc Shang XiaoJing
2022-09-05 10:19   ` Jiri Olsa
2022-09-05 11:22     ` shangxiaojing [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=7bb62639-a94e-907c-7110-aad45dda4db4@huawei.com \
    --to=shangxiaojing@huawei.com \
    --cc=acme@kernel.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=olsajiri@gmail.com \
    --cc=peterz@infradead.org \
    /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;
as well as URLs for NNTP newsgroup(s).