Skip to contentSkip to conversation

perf c2c: Fix memory leak in c2c_he_zalloc()

PATCH In review Yunfeng Ye 2 participants 3 messages Oct 25, 2019 – Nov 26, 2019 perf events

lore
Share & tools
lore

Yunfeng Ye

author
#0 lore raw

PATCH 1/1 perf c2c: Fix memory leak in c2c_he_zalloc()

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")
---
 tools/perf/builtin-c2c.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
tools/perf/builtin-c2c.c +11 -3
index e69f44941aad..ad7d38a9dcbe 100644
@@ -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)
Signature · 1 line
2.7.4
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Yunfeng Ye

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

thanks,
jirka

Quoted 44 lines
---
 tools/perf/builtin-c2c.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
tools/perf/builtin-c2c.c +11 -3
index e69f44941aad..ad7d38a9dcbe 100644
@@ -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)
Signature · 1 line
2.7.4
author
#2 lore raw
Quoted 11 lines · Jiri Olsa
Quoted 7 lines · Yunfeng Ye

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

Is this patch applied? thanks

Quoted 51 lines

thanks,
jirka

Quoted 44 lines
---
 tools/perf/builtin-c2c.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
tools/perf/builtin-c2c.c +11 -3
index e69f44941aad..ad7d38a9dcbe 100644
@@ -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)
Signature · 1 line
2.7.4

.