linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf c2c: Fix memory leak in c2c_he_zalloc()
@ 2019-10-25  9:42 Yunfeng Ye
  2019-10-25 12:01 ` Jiri Olsa
  0 siblings, 1 reply; 3+ messages in thread
From: Yunfeng Ye @ 2019-10-25  9:42 UTC (permalink / raw)
  To: peterz, mingo, acme, mark.rutland, alexander.shishkin, jolsa, namhyung
  Cc: linux-kernel, hushiyuan, linfeilong

A memory leak in c2c_he_zalloc() is found by visual inspection.

Fix this by adding memory free on the error paths in c2c_he_zalloc().

Fixes: 7f834c2e84bb ("perf c2c report: Display node for cacheline address")
Fixes: 1e181b92a2da ("perf c2c report: Add 'node' sort key")
Signed-off-by: Yunfeng Ye <yeyunfeng@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 e69f44941aad..ad7d38a9dcbe 100644
--- a/tools/perf/builtin-c2c.c
+++ b/tools/perf/builtin-c2c.c
@@ -138,21 +138,29 @@ static void *c2c_he_zalloc(size_t size)

 	c2c_he->cpuset = bitmap_alloc(c2c.cpus_cnt);
 	if (!c2c_he->cpuset)
-		return NULL;
+		goto free_c2c_he;

 	c2c_he->nodeset = bitmap_alloc(c2c.nodes_cnt);
 	if (!c2c_he->nodeset)
-		return NULL;
+		goto free_cpuset;

 	c2c_he->node_stats = zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_stats));
 	if (!c2c_he->node_stats)
-		return NULL;
+		goto free_nodeset;

 	init_stats(&c2c_he->cstats.lcl_hitm);
 	init_stats(&c2c_he->cstats.rmt_hitm);
 	init_stats(&c2c_he->cstats.load);

 	return &c2c_he->he;
+
+free_nodeset:
+	free(c2c_he->nodeset);
+free_cpuset:
+	free(c2c_he->cpuset);
+free_c2c_he:
+	free(c2c_he);
+	return NULL;
 }

 static void c2c_he_free(void *he)
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf c2c: Fix memory leak in c2c_he_zalloc()
  2019-10-25  9:42 [PATCH] perf c2c: Fix memory leak in c2c_he_zalloc() Yunfeng Ye
@ 2019-10-25 12:01 ` Jiri Olsa
  2019-11-26  3:00   ` Yunfeng Ye
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Olsa @ 2019-10-25 12:01 UTC (permalink / raw)
  To: Yunfeng Ye
  Cc: peterz, mingo, acme, mark.rutland, alexander.shishkin, namhyung,
	linux-kernel, hushiyuan, linfeilong

On Fri, Oct 25, 2019 at 05:42:47PM +0800, Yunfeng Ye wrote:
> A memory leak in c2c_he_zalloc() is found by visual inspection.
> 
> Fix this by adding memory free on the error paths in c2c_he_zalloc().
> 
> Fixes: 7f834c2e84bb ("perf c2c report: Display node for cacheline address")
> Fixes: 1e181b92a2da ("perf c2c report: Add 'node' sort key")
> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>

Acked-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

> ---
>  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 e69f44941aad..ad7d38a9dcbe 100644
> --- a/tools/perf/builtin-c2c.c
> +++ b/tools/perf/builtin-c2c.c
> @@ -138,21 +138,29 @@ static void *c2c_he_zalloc(size_t size)
> 
>  	c2c_he->cpuset = bitmap_alloc(c2c.cpus_cnt);
>  	if (!c2c_he->cpuset)
> -		return NULL;
> +		goto free_c2c_he;
> 
>  	c2c_he->nodeset = bitmap_alloc(c2c.nodes_cnt);
>  	if (!c2c_he->nodeset)
> -		return NULL;
> +		goto free_cpuset;
> 
>  	c2c_he->node_stats = zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_stats));
>  	if (!c2c_he->node_stats)
> -		return NULL;
> +		goto free_nodeset;
> 
>  	init_stats(&c2c_he->cstats.lcl_hitm);
>  	init_stats(&c2c_he->cstats.rmt_hitm);
>  	init_stats(&c2c_he->cstats.load);
> 
>  	return &c2c_he->he;
> +
> +free_nodeset:
> +	free(c2c_he->nodeset);
> +free_cpuset:
> +	free(c2c_he->cpuset);
> +free_c2c_he:
> +	free(c2c_he);
> +	return NULL;
>  }
> 
>  static void c2c_he_free(void *he)
> -- 
> 2.7.4
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] perf c2c: Fix memory leak in c2c_he_zalloc()
  2019-10-25 12:01 ` Jiri Olsa
@ 2019-11-26  3:00   ` Yunfeng Ye
  0 siblings, 0 replies; 3+ messages in thread
From: Yunfeng Ye @ 2019-11-26  3:00 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: peterz, mingo, acme, mark.rutland, alexander.shishkin, namhyung,
	linux-kernel, hushiyuan, linfeilong, arnaldo.melo



On 2019/10/25 20:01, Jiri Olsa wrote:
> On Fri, Oct 25, 2019 at 05:42:47PM +0800, Yunfeng Ye wrote:
>> A memory leak in c2c_he_zalloc() is found by visual inspection.
>>
>> Fix this by adding memory free on the error paths in c2c_he_zalloc().
>>
>> Fixes: 7f834c2e84bb ("perf c2c report: Display node for cacheline address")
>> Fixes: 1e181b92a2da ("perf c2c report: Add 'node' sort key")
>> Signed-off-by: Yunfeng Ye <yeyunfeng@huawei.com>
> 
> Acked-by: Jiri Olsa <jolsa@kernel.org>
> 

Is this patch applied? thanks

> thanks,
> jirka
> 
>> ---
>>  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 e69f44941aad..ad7d38a9dcbe 100644
>> --- a/tools/perf/builtin-c2c.c
>> +++ b/tools/perf/builtin-c2c.c
>> @@ -138,21 +138,29 @@ static void *c2c_he_zalloc(size_t size)
>>
>>  	c2c_he->cpuset = bitmap_alloc(c2c.cpus_cnt);
>>  	if (!c2c_he->cpuset)
>> -		return NULL;
>> +		goto free_c2c_he;
>>
>>  	c2c_he->nodeset = bitmap_alloc(c2c.nodes_cnt);
>>  	if (!c2c_he->nodeset)
>> -		return NULL;
>> +		goto free_cpuset;
>>
>>  	c2c_he->node_stats = zalloc(c2c.nodes_cnt * sizeof(*c2c_he->node_stats));
>>  	if (!c2c_he->node_stats)
>> -		return NULL;
>> +		goto free_nodeset;
>>
>>  	init_stats(&c2c_he->cstats.lcl_hitm);
>>  	init_stats(&c2c_he->cstats.rmt_hitm);
>>  	init_stats(&c2c_he->cstats.load);
>>
>>  	return &c2c_he->he;
>> +
>> +free_nodeset:
>> +	free(c2c_he->nodeset);
>> +free_cpuset:
>> +	free(c2c_he->cpuset);
>> +free_c2c_he:
>> +	free(c2c_he);
>> +	return NULL;
>>  }
>>
>>  static void c2c_he_free(void *he)
>> -- 
>> 2.7.4
>>
> 
> 
> .
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-11-26  3:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-25  9:42 [PATCH] perf c2c: Fix memory leak in c2c_he_zalloc() Yunfeng Ye
2019-10-25 12:01 ` Jiri Olsa
2019-11-26  3:00   ` Yunfeng Ye

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).