perf c2c: Fix memory leaks on output fields
Namhyung Kim
maintainerPATCH v2 1/1 perf c2c: Fix memory leaks on output fields
The perf_hpp_list was not freed after use. Let's add it for the main c2c hists list in perf c2c report and a local list in print_pareto().
Previously it was detected by ASAN like below.
=================================================================
==42183==ERROR: LeakSanitizer: detected memory leaks
Indirect leak of 1064 byte(s) in 7 object(s) allocated from:
#0 0x7f17334ef24f in calloc (/lib64/libasan.so.8+0xef24f) (BuildId: 61e8165ca90f7a4f06b73f064a938c76deaae079)
#1 0x0000005fa099 in zalloc ../../lib/zalloc.c:8
#2 0x0000004faf6d in get_format tools/perf/builtin-c2c.c:1978
#3 0x0000004fb45e in c2c_hists__init_output tools/perf/builtin-c2c.c:2004
#4 0x0000004fb7de in __hpp_list__parse tools/perf/builtin-c2c.c:2047
#5 0x0000004fbae9 in hpp_list__parse tools/perf/builtin-c2c.c:2085
#6 0x0000004fee13 in print_pareto tools/perf/builtin-c2c.c:2563
#7 0x0000004ffcd7 in perf_c2c__hists_fprintf tools/perf/builtin-c2c.c:2708
#8 0x000000500ab5 in perf_c2c_display tools/perf/builtin-c2c.c:2949
#9 0x0000005045c3 in perf_c2c__report tools/perf/builtin-c2c.c:3522
#10 0x000000505caa in cmd_c2c tools/perf/builtin-c2c.c:3676
#11 0x0000005df50e in run_builtin tools/perf/perf.c:383
#12 0x0000005df9b1 in handle_internal_command tools/perf/perf.c:436
#13 0x0000005dfd7f in run_argv tools/perf/perf.c:480
#14 0x0000005e02d6 in main tools/perf/perf.c:581
#15 0x7f1729450680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: 85075e2ae2e13352a1413d41c327dacf6461526c)
#16 0x7f1729450797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: 85075e2ae2e13352a1413d41c327dacf6461526c)
#17 0x000000409c34 in _start (tools/perf/perf+0x409c34) (BuildId: 36a64600776d92e4ab7dfd5ca20c92280d72a645)SUMMARY: AddressSanitizer: 1064 byte(s) leaked in 7 allocation(s).
--- tools/perf/builtin-c2c.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
tools/perf/builtin-c2c.c +13 -3
@@ -2155,6 +2155,11 @@ static int c2c_hists__reinit(struct c2c_hists *c2c_hists,return ret; } +static void c2c_hists__exit (struct c2c_hists *c2c_hists) +{ +perf_hpp__reset_output_field (&c2c_hists->list); +} +#define DISPLAY_LINE_LIMIT 0.001static u8 filter_display (u32 val,u32 sum)
@@ -2563,7 +2568,7 @@ static void print_pareto(FILE *out, struct perf_env *env) ret =hpp_list__parse (&hpp_list, cl_output,/*evlist=*/ NULL , env);if (WARN_ONCE (ret,"failed to setup sort entries\n" )) -return ; + goto out; nd =rb_first_cached (&c2c.hists.hists.entries);
@@ -2577,6 +2582,9 @@ static void print_pareto(FILE *out, struct perf_env *env) c2c_he = container_of(he, struct c2c_hist_entry, he);print_cacheline (c2c_he->hists, he, &hpp_list, out); } + +out: +perf_hpp__reset_output_field (&hpp_list); }static void print_c2c_info (FILE *out,struct perf_session *session)
@@ -3378,12 +3386,12 @@ static int perf_c2c__report(int argc, const char **argv) err =setup_nodes (session);if (err) {pr_err ("Failed setup nodes\n" ); - goto out_session; + goto out_hists; } err =mem2node__init (&c2c.mem2node, env);if (err) - goto out_session; + goto out_hists; err =setup_callchain (session->evlist);if (err)
@@ -3525,6 +3533,8 @@ static int perf_c2c__report(int argc, const char **argv)free (output_str); out_mem2node:mem2node__exit (&c2c.mem2node); +out_hists: +c2c_hists__exit (&c2c.hists); out_session:perf_session__delete (session); out:
Signature · 1 line
2.56.0.176.g3575e65682-goog
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 15 lines
The
perf_hpp_listwas not freed after use. Let's add it for the main c2c hists list in perf c2c report and a local list inprint_pareto().Previously it was detected by ASAN like below.
=================================================================
==42183==ERROR: LeakSanitizer: detected memory leaksIndirect leak of 1064 byte(s) in 7 object(s) allocated from:
#0 0x7f17334ef24f in calloc (/lib64/libasan.so.8+0xef24f) (BuildId: 61e8165ca90f7a4f06b73f064a938c76deaae079) #1 0x0000005fa099 in zalloc ../../lib/zalloc.c:8 #2 0x0000004faf6d in get_format tools/perf/builtin-c2c.c:1978 #3 0x0000004fb45e in c2c_hists__init_output tools/perf/builtin-c2c.c:2004 #4 0x0000004fb7de in __hpp_list__parse tools/perf/builtin-c2c.c:2047 #5 0x0000004fbae9 in hpp_list__parse tools/perf/builtin-c2c.c:2085
Quoted 6 lines
[ ... ]
SUMMARY: AddressSanitizer: 1064 byte(s) leaked in 7 allocation(s).
Fixes c75540e3160f ("perf c2c report: Add dimension support")Signed-off-by Namhyung Kim <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 97 lines · Namhyung Kim
The
perf_hpp_listwas not freed after use. Let's add it for the main c2c hists list in perf c2c report and a local list inprint_pareto().Previously it was detected by ASAN like below.
=================================================================
==42183==ERROR: LeakSanitizer: detected memory leaksIndirect leak of 1064 byte(s) in 7 object(s) allocated from:
#0 0x7f17334ef24f in calloc (/lib64/libasan.so.8+0xef24f) (BuildId: 61e8165ca90f7a4f06b73f064a938c76deaae079) #1 0x0000005fa099 in zalloc ../../lib/zalloc.c:8 #2 0x0000004faf6d in get_format tools/perf/builtin-c2c.c:1978 #3 0x0000004fb45e in c2c_hists__init_output tools/perf/builtin-c2c.c:2004 #4 0x0000004fb7de in __hpp_list__parse tools/perf/builtin-c2c.c:2047 #5 0x0000004fbae9 in hpp_list__parse tools/perf/builtin-c2c.c:2085 #6 0x0000004fee13 in print_pareto tools/perf/builtin-c2c.c:2563 #7 0x0000004ffcd7 in perf_c2c__hists_fprintf tools/perf/builtin-c2c.c:2708 #8 0x000000500ab5 in perf_c2c_display tools/perf/builtin-c2c.c:2949 #9 0x0000005045c3 in perf_c2c__report tools/perf/builtin-c2c.c:3522 #10 0x000000505caa in cmd_c2c tools/perf/builtin-c2c.c:3676 #11 0x0000005df50e in run_builtin tools/perf/perf.c:383 #12 0x0000005df9b1 in handle_internal_command tools/perf/perf.c:436 #13 0x0000005dfd7f in run_argv tools/perf/perf.c:480 #14 0x0000005e02d6 in main tools/perf/perf.c:581 #15 0x7f1729450680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: 85075e2ae2e13352a1413d41c327dacf6461526c) #16 0x7f1729450797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: 85075e2ae2e13352a1413d41c327dacf6461526c) #17 0x000000409c34 in _start (tools/perf/perf+0x409c34) (BuildId: 36a64600776d92e4ab7dfd5ca20c92280d72a645)SUMMARY: AddressSanitizer: 1064 byte(s) leaked in 7 allocation(s).
Fixes c75540e3160f ("perf c2c report: Add dimension support")Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/builtin-c2c.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)tools/perf/builtin-c2c.c +13
-3@@ -2155,6 +2155,11 @@ static int c2c_hists__reinit(struct c2c_hists *c2c_hists,return ret; } +static void c2c_hists__exit (struct c2c_hists *c2c_hists) +{ +perf_hpp__reset_output_field (&c2c_hists->list); +} +#define DISPLAY_LINE_LIMIT 0.001static u8 filter_display (u32 val,u32 sum)@@ -2563,7 +2568,7 @@ static void print_pareto(FILE *out, struct perf_env *env) ret =hpp_list__parse (&hpp_list, cl_output,/*evlist=*/ NULL , env);if (WARN_ONCE (ret,"failed to setup sort entries\n" )) -return ; + goto out; nd =rb_first_cached (&c2c.hists.hists.entries);@@ -2577,6 +2582,9 @@ static void print_pareto(FILE *out, struct perf_env *env) c2c_he = container_of(he, struct c2c_hist_entry, he);print_cacheline (c2c_he->hists, he, &hpp_list, out); } + +out: +perf_hpp__reset_output_field (&hpp_list); }static void print_c2c_info (FILE *out,struct perf_session *session)@@ -3378,12 +3386,12 @@ static int perf_c2c__report(int argc, const char **argv) err =setup_nodes (session);if (err) {pr_err ("Failed setup nodes\n" ); - goto out_session; + goto out_hists; } err =mem2node__init (&c2c.mem2node, env);if (err) - goto out_session; + goto out_hists; err =setup_callchain (session->evlist);if (err)@@ -3525,6 +3533,8 @@ static int perf_c2c__report(int argc, const char **argv)free (output_str); out_mem2node:mem2node__exit (&c2c.mem2node); +out_hists: +c2c_hists__exit (&c2c.hists); out_session:perf_session__delete (session); out:Signature · 1 line
2.56.0.176.g3575e65682-goog
Signature · 1 line
Aaron Tomlin
Quoted 28 lines · Namhyung Kim
The
perf_hpp_listwas not freed after use. Let's add it for the main c2c hists list in perf c2c report and a local list inprint_pareto().Previously it was detected by ASAN like below.
=================================================================
==42183==ERROR: LeakSanitizer: detected memory leaksIndirect leak of 1064 byte(s) in 7 object(s) allocated from:
#0 0x7f17334ef24f in calloc (/lib64/libasan.so.8+0xef24f) (BuildId: 61e8165ca90f7a4f06b73f064a938c76deaae079) #1 0x0000005fa099 in zalloc ../../lib/zalloc.c:8 #2 0x0000004faf6d in get_format tools/perf/builtin-c2c.c:1978 #3 0x0000004fb45e in c2c_hists__init_output tools/perf/builtin-c2c.c:2004 #4 0x0000004fb7de in __hpp_list__parse tools/perf/builtin-c2c.c:2047 #5 0x0000004fbae9 in hpp_list__parse tools/perf/builtin-c2c.c:2085 #6 0x0000004fee13 in print_pareto tools/perf/builtin-c2c.c:2563 #7 0x0000004ffcd7 in perf_c2c__hists_fprintf tools/perf/builtin-c2c.c:2708 #8 0x000000500ab5 in perf_c2c_display tools/perf/builtin-c2c.c:2949 #9 0x0000005045c3 in perf_c2c__report tools/perf/builtin-c2c.c:3522 #10 0x000000505caa in cmd_c2c tools/perf/builtin-c2c.c:3676 #11 0x0000005df50e in run_builtin tools/perf/perf.c:383 #12 0x0000005df9b1 in handle_internal_command tools/perf/perf.c:436 #13 0x0000005dfd7f in run_argv tools/perf/perf.c:480 #14 0x0000005e02d6 in main tools/perf/perf.c:581 #15 0x7f1729450680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: 85075e2ae2e13352a1413d41c327dacf6461526c) #16 0x7f1729450797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: 85075e2ae2e13352a1413d41c327dacf6461526c) #17 0x000000409c34 in _start (tools/perf/perf+0x409c34) (BuildId: 36a64600776d92e4ab7dfd5ca20c92280d72a645)
Quoted 4 lines
SUMMARY: AddressSanitizer: 1064 byte(s) leaked in 7 allocation(s).
Fixes c75540e3160f ("perf c2c report: Add dimension support")Signed-off-by Namhyung Kim <[email protected]>
Quoted 30 lines · Dmitry Ilvokhin
Quoted 28 lines · Namhyung Kim
The
perf_hpp_listwas not freed after use. Let's add it for the main c2c hists list in perf c2c report and a local list inprint_pareto().Previously it was detected by ASAN like below.
=================================================================
==42183==ERROR: LeakSanitizer: detected memory leaksIndirect leak of 1064 byte(s) in 7 object(s) allocated from:
#0 0x7f17334ef24f in calloc (/lib64/libasan.so.8+0xef24f) (BuildId: 61e8165ca90f7a4f06b73f064a938c76deaae079) #1 0x0000005fa099 in zalloc ../../lib/zalloc.c:8 #2 0x0000004faf6d in get_format tools/perf/builtin-c2c.c:1978 #3 0x0000004fb45e in c2c_hists__init_output tools/perf/builtin-c2c.c:2004 #4 0x0000004fb7de in __hpp_list__parse tools/perf/builtin-c2c.c:2047 #5 0x0000004fbae9 in hpp_list__parse tools/perf/builtin-c2c.c:2085 #6 0x0000004fee13 in print_pareto tools/perf/builtin-c2c.c:2563 #7 0x0000004ffcd7 in perf_c2c__hists_fprintf tools/perf/builtin-c2c.c:2708 #8 0x000000500ab5 in perf_c2c_display tools/perf/builtin-c2c.c:2949 #9 0x0000005045c3 in perf_c2c__report tools/perf/builtin-c2c.c:3522 #10 0x000000505caa in cmd_c2c tools/perf/builtin-c2c.c:3676 #11 0x0000005df50e in run_builtin tools/perf/perf.c:383 #12 0x0000005df9b1 in handle_internal_command tools/perf/perf.c:436 #13 0x0000005dfd7f in run_argv tools/perf/perf.c:480 #14 0x0000005e02d6 in main tools/perf/perf.c:581 #15 0x7f1729450680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: 85075e2ae2e13352a1413d41c327dacf6461526c) #16 0x7f1729450797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: 85075e2ae2e13352a1413d41c327dacf6461526c) #17 0x000000409c34 in _start (tools/perf/perf+0x409c34) (BuildId: 36a64600776d92e4ab7dfd5ca20c92280d72a645)
Quoted 6 lines
Quoted 4 lines
SUMMARY: AddressSanitizer: 1064 byte(s) leaked in 7 allocation(s).
Fixes c75540e3160f ("perf c2c report: Add dimension support")Signed-off-by Namhyung Kim <[email protected]>Reviewed-by Dmitry Ilvokhin <[email protected]>
Thanks,
Ian
Quoted 31 lines · Ian Rogers
Quoted 30 lines · Dmitry Ilvokhin
Quoted 28 lines · Namhyung Kim
The
perf_hpp_listwas not freed after use. Let's add it for the main c2c hists list in perf c2c report and a local list inprint_pareto().Previously it was detected by ASAN like below.
=================================================================
==42183==ERROR: LeakSanitizer: detected memory leaksIndirect leak of 1064 byte(s) in 7 object(s) allocated from:
#0 0x7f17334ef24f in calloc (/lib64/libasan.so.8+0xef24f) (BuildId: 61e8165ca90f7a4f06b73f064a938c76deaae079) #1 0x0000005fa099 in zalloc ../../lib/zalloc.c:8 #2 0x0000004faf6d in get_format tools/perf/builtin-c2c.c:1978 #3 0x0000004fb45e in c2c_hists__init_output tools/perf/builtin-c2c.c:2004 #4 0x0000004fb7de in __hpp_list__parse tools/perf/builtin-c2c.c:2047 #5 0x0000004fbae9 in hpp_list__parse tools/perf/builtin-c2c.c:2085 #6 0x0000004fee13 in print_pareto tools/perf/builtin-c2c.c:2563 #7 0x0000004ffcd7 in perf_c2c__hists_fprintf tools/perf/builtin-c2c.c:2708 #8 0x000000500ab5 in perf_c2c_display tools/perf/builtin-c2c.c:2949 #9 0x0000005045c3 in perf_c2c__report tools/perf/builtin-c2c.c:3522 #10 0x000000505caa in cmd_c2c tools/perf/builtin-c2c.c:3676 #11 0x0000005df50e in run_builtin tools/perf/perf.c:383 #12 0x0000005df9b1 in handle_internal_command tools/perf/perf.c:436 #13 0x0000005dfd7f in run_argv tools/perf/perf.c:480 #14 0x0000005e02d6 in main tools/perf/perf.c:581 #15 0x7f1729450680 in __libc_start_call_main (/lib64/libc.so.6+0x3680) (BuildId: 85075e2ae2e13352a1413d41c327dacf6461526c) #16 0x7f1729450797 in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x3797) (BuildId: 85075e2ae2e13352a1413d41c327dacf6461526c) #17 0x000000409c34 in _start (tools/perf/perf+0x409c34) (BuildId: 36a64600776d92e4ab7dfd5ca20c92280d72a645)
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
SUMMARY: AddressSanitizer: 1064 byte(s) leaked in 7 allocation(s).
Fixes c75540e3160f ("perf c2c report: Add dimension support")Signed-off-by Namhyung Kim <[email protected]>Reviewed-by Dmitry Ilvokhin <[email protected]>Reviewed-by Ian Rogers <[email protected]>
Thanks, applied to perf-tools-next, for v7.4.
- Arnaldo