perf session: add missing evlist__delete when deleting a session
PATCH v2 1/1 perf session: add missing evlist__delete when deleting a session
ASan reports a memory leak caused by evlist not being deleted on exit in perf-report, perf-script and perf-data.
The problem is caused by evlist->session not being deleted, which is allocated in perf_session__read_header, called in perf_session__new if perf_data is in read mode.
In case of write mode, the session->evlist is filled by the caller. This patch solves the problem by calling evlist__delete in perf_session__delete if perf_data is in read mode.
Changes in v2:
- call evlist__delete from within perf_session__delete
v1: https://lore.kernel.org/lkml/[email protected]/
ASan report follows:
$ ./perf script report flamegraph ================================================================= ==227640==ERROR: LeakSanitizer: detected memory leaks
<SNIP unrelated>
Indirect leak of 2704 byte(s) in 1 object(s) allocated from:
#0 0x4f4137 in calloc (/home/user/linux/tools/perf/perf+0x4f4137)
#1 0xbe3d56 in zalloc /home/user/linux/tools/lib/perf/../../lib/zalloc.c:8:9
#2 0x7f999e in evlist__new /home/user/linux/tools/perf/util/evlist.c:77:26
#3 0x8ad938 in perf_session__read_header /home/user/linux/tools/perf/util/header.c:3797:20
#4 0x8ec714 in perf_session__open /home/user/linux/tools/perf/util/session.c:109:6
#5 0x8ebe83 in perf_session__new /home/user/linux/tools/perf/util/session.c:213:10
#6 0x60c6de in cmd_script /home/user/linux/tools/perf/builtin-script.c:3856:12
#7 0x7b2930 in run_builtin /home/user/linux/tools/perf/perf.c:313:11
#8 0x7b120f in handle_internal_command /home/user/linux/tools/perf/perf.c:365:8
#9 0x7b2493 in run_argv /home/user/linux/tools/perf/perf.c:409:2
#10 0x7b0c89 in main /home/user/linux/tools/perf/perf.c:539:3
#11 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)Indirect leak of 568 byte(s) in 1 object(s) allocated from:
#0 0x4f4137 in calloc (/home/user/linux/tools/perf/perf+0x4f4137)
#1 0xbe3d56 in zalloc /home/user/linux/tools/lib/perf/../../lib/zalloc.c:8:9
#2 0x80ce88 in evsel__new_idx /home/user/linux/tools/perf/util/evsel.c:268:24
#3 0x8aed93 in evsel__new /home/user/linux/tools/perf/util/evsel.h:210:9
#4 0x8ae07e in perf_session__read_header /home/user/linux/tools/perf/util/header.c:3853:11
#5 0x8ec714 in perf_session__open /home/user/linux/tools/perf/util/session.c:109:6
#6 0x8ebe83 in perf_session__new /home/user/linux/tools/perf/util/session.c:213:10
#7 0x60c6de in cmd_script /home/user/linux/tools/perf/builtin-script.c:3856:12
#8 0x7b2930 in run_builtin /home/user/linux/tools/perf/perf.c:313:11
#9 0x7b120f in handle_internal_command /home/user/linux/tools/perf/perf.c:365:8
#10 0x7b2493 in run_argv /home/user/linux/tools/perf/perf.c:409:2
#11 0x7b0c89 in main /home/user/linux/tools/perf/perf.c:539:3
#12 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)Indirect leak of 264 byte(s) in 1 object(s) allocated from:
#0 0x4f4137 in calloc (/home/user/linux/tools/perf/perf+0x4f4137)
#1 0xbe3d56 in zalloc /home/user/linux/tools/lib/perf/../../lib/zalloc.c:8:9
#2 0xbe3e70 in xyarray__new /home/user/linux/tools/lib/perf/xyarray.c:10:23
#3 0xbd7754 in perf_evsel__alloc_id /home/user/linux/tools/lib/perf/evsel.c:361:21
#4 0x8ae201 in perf_session__read_header /home/user/linux/tools/perf/util/header.c:3871:7
#5 0x8ec714 in perf_session__open /home/user/linux/tools/perf/util/session.c:109:6
#6 0x8ebe83 in perf_session__new /home/user/linux/tools/perf/util/session.c:213:10
#7 0x60c6de in cmd_script /home/user/linux/tools/perf/builtin-script.c:3856:12
#8 0x7b2930 in run_builtin /home/user/linux/tools/perf/perf.c:313:11
#9 0x7b120f in handle_internal_command /home/user/linux/tools/perf/perf.c:365:8
#10 0x7b2493 in run_argv /home/user/linux/tools/perf/perf.c:409:2
#11 0x7b0c89 in main /home/user/linux/tools/perf/perf.c:539:3
#12 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)Indirect leak of 32 byte(s) in 1 object(s) allocated from:
#0 0x4f4137 in calloc (/home/user/linux/tools/perf/perf+0x4f4137)
#1 0xbe3d56 in zalloc /home/user/linux/tools/lib/perf/../../lib/zalloc.c:8:9
#2 0xbd77e0 in perf_evsel__alloc_id /home/user/linux/tools/lib/perf/evsel.c:365:14
#3 0x8ae201 in perf_session__read_header /home/user/linux/tools/perf/util/header.c:3871:7
#4 0x8ec714 in perf_session__open /home/user/linux/tools/perf/util/session.c:109:6
#5 0x8ebe83 in perf_session__new /home/user/linux/tools/perf/util/session.c:213:10
#6 0x60c6de in cmd_script /home/user/linux/tools/perf/builtin-script.c:3856:12
#7 0x7b2930 in run_builtin /home/user/linux/tools/perf/perf.c:313:11
#8 0x7b120f in handle_internal_command /home/user/linux/tools/perf/perf.c:365:8
#9 0x7b2493 in run_argv /home/user/linux/tools/perf/perf.c:409:2
#10 0x7b0c89 in main /home/user/linux/tools/perf/perf.c:539:3
#11 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)Indirect leak of 7 byte(s) in 1 object(s) allocated from:
#0 0x4b8207 in strdup (/home/user/linux/tools/perf/perf+0x4b8207)
#1 0x8b4459 in evlist__set_event_name /home/user/linux/tools/perf/util/header.c:2292:16
#2 0x89d862 in process_event_desc /home/user/linux/tools/perf/util/header.c:2313:3
#3 0x8af319 in perf_file_section__process /home/user/linux/tools/perf/util/header.c:3651:9
#4 0x8aa6e9 in perf_header__process_sections /home/user/linux/tools/perf/util/header.c:3427:9
#5 0x8ae3e7 in perf_session__read_header /home/user/linux/tools/perf/util/header.c:3886:2
#6 0x8ec714 in perf_session__open /home/user/linux/tools/perf/util/session.c:109:6
#7 0x8ebe83 in perf_session__new /home/user/linux/tools/perf/util/session.c:213:10
#8 0x60c6de in cmd_script /home/user/linux/tools/perf/builtin-script.c:3856:12
#9 0x7b2930 in run_builtin /home/user/linux/tools/perf/perf.c:313:11
#10 0x7b120f in handle_internal_command /home/user/linux/tools/perf/perf.c:365:8
#11 0x7b2493 in run_argv /home/user/linux/tools/perf/perf.c:409:2
#12 0x7b0c89 in main /home/user/linux/tools/perf/perf.c:539:3
#13 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)SUMMARY: AddressSanitizer: 3728 byte(s) leaked in 7 allocation(s).
--- tools/perf/util/session.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
tools/perf/util/session.c +4 -1
@@ -301,8 +301,11 @@ void perf_session__delete(struct perf_session *session)perf_session__release_decomp_events (session);perf_env__exit (&session->header.env);machines__exit (&session->machines); -if (session->data) +if (session->data) { +if (perf_data__is_read (session->data)) +evlist__delete (session->evlist);perf_data__close (session->data); + }free (session); }
Signature · 1 line
2.31.1
Quoted 9 lines · Riccardo Mancini
ASan reports a memory leak caused by evlist not being deleted on exit in perf-report, perf-script and perf-data.
The problem is caused byevlist->sessionnot being deleted, which is allocated inperf_session__read_header, called inperf_session__newifperf_datais in read mode.
In case of write mode, thesession->evlistis filled by the caller. This patch solves the problem by callingevlist__deleteinperf_session__deleteifperf_datais in read mode.
It is messy that in read mode the session owns the evlist, but otherwise not. Imo, it'd be nice to make the ownership unconditional.
Thanks,
Ian
Quoted 114 lines
Changes in v2:
- callevlist__deletefrom withinperf_session__deletev1: https://lore.kernel.org/lkml/[email protected]/
ASan report follows:
$ ./perf script report flamegraph ================================================================= ==227640==ERROR: LeakSanitizer: detected memory leaks<SNIP unrelated>
Indirect leak of 2704 byte(s) in 1 object(s) allocated from:
#0 0x4f4137 in calloc (/home/user/linux/tools/perf/perf+0x4f4137) #1 0xbe3d56 in zalloc /home/user/linux/tools/lib/perf/../../lib/zalloc.c:8:9 #2 0x7f999e in evlist__new /home/user/linux/tools/perf/util/evlist.c:77:26 #3 0x8ad938 in perf_session__read_header /home/user/linux/tools/perf/util/header.c:3797:20 #4 0x8ec714 in perf_session__open /home/user/linux/tools/perf/util/session.c:109:6 #5 0x8ebe83 in perf_session__new /home/user/linux/tools/perf/util/session.c:213:10 #6 0x60c6de in cmd_script /home/user/linux/tools/perf/builtin-script.c:3856:12 #7 0x7b2930 in run_builtin /home/user/linux/tools/perf/perf.c:313:11 #8 0x7b120f in handle_internal_command /home/user/linux/tools/perf/perf.c:365:8 #9 0x7b2493 in run_argv /home/user/linux/tools/perf/perf.c:409:2 #10 0x7b0c89 in main /home/user/linux/tools/perf/perf.c:539:3 #11 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)Indirect leak of 568 byte(s) in 1 object(s) allocated from:
#0 0x4f4137 in calloc (/home/user/linux/tools/perf/perf+0x4f4137) #1 0xbe3d56 in zalloc /home/user/linux/tools/lib/perf/../../lib/zalloc.c:8:9 #2 0x80ce88 in evsel__new_idx /home/user/linux/tools/perf/util/evsel.c:268:24 #3 0x8aed93 in evsel__new /home/user/linux/tools/perf/util/evsel.h:210:9 #4 0x8ae07e in perf_session__read_header /home/user/linux/tools/perf/util/header.c:3853:11 #5 0x8ec714 in perf_session__open /home/user/linux/tools/perf/util/session.c:109:6 #6 0x8ebe83 in perf_session__new /home/user/linux/tools/perf/util/session.c:213:10 #7 0x60c6de in cmd_script /home/user/linux/tools/perf/builtin-script.c:3856:12 #8 0x7b2930 in run_builtin /home/user/linux/tools/perf/perf.c:313:11 #9 0x7b120f in handle_internal_command /home/user/linux/tools/perf/perf.c:365:8 #10 0x7b2493 in run_argv /home/user/linux/tools/perf/perf.c:409:2 #11 0x7b0c89 in main /home/user/linux/tools/perf/perf.c:539:3 #12 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)Indirect leak of 264 byte(s) in 1 object(s) allocated from:
#0 0x4f4137 in calloc (/home/user/linux/tools/perf/perf+0x4f4137) #1 0xbe3d56 in zalloc /home/user/linux/tools/lib/perf/../../lib/zalloc.c:8:9 #2 0xbe3e70 in xyarray__new /home/user/linux/tools/lib/perf/xyarray.c:10:23 #3 0xbd7754 in perf_evsel__alloc_id /home/user/linux/tools/lib/perf/evsel.c:361:21 #4 0x8ae201 in perf_session__read_header /home/user/linux/tools/perf/util/header.c:3871:7 #5 0x8ec714 in perf_session__open /home/user/linux/tools/perf/util/session.c:109:6 #6 0x8ebe83 in perf_session__new /home/user/linux/tools/perf/util/session.c:213:10 #7 0x60c6de in cmd_script /home/user/linux/tools/perf/builtin-script.c:3856:12 #8 0x7b2930 in run_builtin /home/user/linux/tools/perf/perf.c:313:11 #9 0x7b120f in handle_internal_command /home/user/linux/tools/perf/perf.c:365:8 #10 0x7b2493 in run_argv /home/user/linux/tools/perf/perf.c:409:2 #11 0x7b0c89 in main /home/user/linux/tools/perf/perf.c:539:3 #12 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)Indirect leak of 32 byte(s) in 1 object(s) allocated from:
#0 0x4f4137 in calloc (/home/user/linux/tools/perf/perf+0x4f4137) #1 0xbe3d56 in zalloc /home/user/linux/tools/lib/perf/../../lib/zalloc.c:8:9 #2 0xbd77e0 in perf_evsel__alloc_id /home/user/linux/tools/lib/perf/evsel.c:365:14 #3 0x8ae201 in perf_session__read_header /home/user/linux/tools/perf/util/header.c:3871:7 #4 0x8ec714 in perf_session__open /home/user/linux/tools/perf/util/session.c:109:6 #5 0x8ebe83 in perf_session__new /home/user/linux/tools/perf/util/session.c:213:10 #6 0x60c6de in cmd_script /home/user/linux/tools/perf/builtin-script.c:3856:12 #7 0x7b2930 in run_builtin /home/user/linux/tools/perf/perf.c:313:11 #8 0x7b120f in handle_internal_command /home/user/linux/tools/perf/perf.c:365:8 #9 0x7b2493 in run_argv /home/user/linux/tools/perf/perf.c:409:2 #10 0x7b0c89 in main /home/user/linux/tools/perf/perf.c:539:3 #11 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)Indirect leak of 7 byte(s) in 1 object(s) allocated from:
#0 0x4b8207 in strdup (/home/user/linux/tools/perf/perf+0x4b8207) #1 0x8b4459 in evlist__set_event_name /home/user/linux/tools/perf/util/header.c:2292:16 #2 0x89d862 in process_event_desc /home/user/linux/tools/perf/util/header.c:2313:3 #3 0x8af319 in perf_file_section__process /home/user/linux/tools/perf/util/header.c:3651:9 #4 0x8aa6e9 in perf_header__process_sections /home/user/linux/tools/perf/util/header.c:3427:9 #5 0x8ae3e7 in perf_session__read_header /home/user/linux/tools/perf/util/header.c:3886:2 #6 0x8ec714 in perf_session__open /home/user/linux/tools/perf/util/session.c:109:6 #7 0x8ebe83 in perf_session__new /home/user/linux/tools/perf/util/session.c:213:10 #8 0x60c6de in cmd_script /home/user/linux/tools/perf/builtin-script.c:3856:12 #9 0x7b2930 in run_builtin /home/user/linux/tools/perf/perf.c:313:11 #10 0x7b120f in handle_internal_command /home/user/linux/tools/perf/perf.c:365:8 #11 0x7b2493 in run_argv /home/user/linux/tools/perf/perf.c:409:2 #12 0x7b0c89 in main /home/user/linux/tools/perf/perf.c:539:3 #13 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)SUMMARY: AddressSanitizer: 3728 byte(s) leaked in 7 allocation(s).
Signed-off-by Riccardo Mancini <[email protected]>--- tools/perf/util/session.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tools/perf/util/session.c +4
-2@@ -301,8 +301,11 @@ void perf_session__delete(struct perf_session *session)perf_session__release_decomp_events (session);perf_env__exit (&session->header.env);machines__exit (&session->machines); -if (session->data) +if (session->data) { +if (perf_data__is_read (session->data)) +evlist__delete (session->evlist);perf_data__close (session->data); + }free (session); } --2.31.1
Jiri Olsa
Acked-byQuoted 10 lines · Ian Rogers
Quoted 9 lines · Riccardo Mancini
ASan reports a memory leak caused by evlist not being deleted on exit in perf-report, perf-script and perf-data.
The problem is caused byevlist->sessionnot being deleted, which is allocated inperf_session__read_header, called inperf_session__newifperf_datais in read mode.
In case of write mode, thesession->evlistis filled by the caller. This patch solves the problem by callingevlist__deleteinperf_session__deleteifperf_datais in read mode.
ugh, I'm surprised we did not free that.. and can't find in git log we ever did ;-) I briefly check commands using sessions and looks like it's correct
Quoted 5 lines
Acked-by Ian Rogers <[email protected]>It is messy that in read mode the session owns the evlist, but otherwise not. Imo, it'd be nice to make the ownership unconditional.
yep, would be nice
thanks,
jirka
Quoted 119 lines
Thanks,
IanQuoted 114 lines
Changes in v2:
- callevlist__deletefrom withinperf_session__deletev1: https://lore.kernel.org/lkml/[email protected]/
ASan report follows:
$ ./perf script report flamegraph ================================================================= ==227640==ERROR: LeakSanitizer: detected memory leaks<SNIP unrelated>
Indirect leak of 2704 byte(s) in 1 object(s) allocated from:
#0 0x4f4137 in calloc (/home/user/linux/tools/perf/perf+0x4f4137) #1 0xbe3d56 in zalloc /home/user/linux/tools/lib/perf/../../lib/zalloc.c:8:9 #2 0x7f999e in evlist__new /home/user/linux/tools/perf/util/evlist.c:77:26 #3 0x8ad938 in perf_session__read_header /home/user/linux/tools/perf/util/header.c:3797:20 #4 0x8ec714 in perf_session__open /home/user/linux/tools/perf/util/session.c:109:6 #5 0x8ebe83 in perf_session__new /home/user/linux/tools/perf/util/session.c:213:10 #6 0x60c6de in cmd_script /home/user/linux/tools/perf/builtin-script.c:3856:12 #7 0x7b2930 in run_builtin /home/user/linux/tools/perf/perf.c:313:11 #8 0x7b120f in handle_internal_command /home/user/linux/tools/perf/perf.c:365:8 #9 0x7b2493 in run_argv /home/user/linux/tools/perf/perf.c:409:2 #10 0x7b0c89 in main /home/user/linux/tools/perf/perf.c:539:3 #11 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)Indirect leak of 568 byte(s) in 1 object(s) allocated from:
#0 0x4f4137 in calloc (/home/user/linux/tools/perf/perf+0x4f4137) #1 0xbe3d56 in zalloc /home/user/linux/tools/lib/perf/../../lib/zalloc.c:8:9 #2 0x80ce88 in evsel__new_idx /home/user/linux/tools/perf/util/evsel.c:268:24 #3 0x8aed93 in evsel__new /home/user/linux/tools/perf/util/evsel.h:210:9 #4 0x8ae07e in perf_session__read_header /home/user/linux/tools/perf/util/header.c:3853:11 #5 0x8ec714 in perf_session__open /home/user/linux/tools/perf/util/session.c:109:6 #6 0x8ebe83 in perf_session__new /home/user/linux/tools/perf/util/session.c:213:10 #7 0x60c6de in cmd_script /home/user/linux/tools/perf/builtin-script.c:3856:12 #8 0x7b2930 in run_builtin /home/user/linux/tools/perf/perf.c:313:11 #9 0x7b120f in handle_internal_command /home/user/linux/tools/perf/perf.c:365:8 #10 0x7b2493 in run_argv /home/user/linux/tools/perf/perf.c:409:2 #11 0x7b0c89 in main /home/user/linux/tools/perf/perf.c:539:3 #12 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)Indirect leak of 264 byte(s) in 1 object(s) allocated from:
#0 0x4f4137 in calloc (/home/user/linux/tools/perf/perf+0x4f4137) #1 0xbe3d56 in zalloc /home/user/linux/tools/lib/perf/../../lib/zalloc.c:8:9 #2 0xbe3e70 in xyarray__new /home/user/linux/tools/lib/perf/xyarray.c:10:23 #3 0xbd7754 in perf_evsel__alloc_id /home/user/linux/tools/lib/perf/evsel.c:361:21 #4 0x8ae201 in perf_session__read_header /home/user/linux/tools/perf/util/header.c:3871:7 #5 0x8ec714 in perf_session__open /home/user/linux/tools/perf/util/session.c:109:6 #6 0x8ebe83 in perf_session__new /home/user/linux/tools/perf/util/session.c:213:10 #7 0x60c6de in cmd_script /home/user/linux/tools/perf/builtin-script.c:3856:12 #8 0x7b2930 in run_builtin /home/user/linux/tools/perf/perf.c:313:11 #9 0x7b120f in handle_internal_command /home/user/linux/tools/perf/perf.c:365:8 #10 0x7b2493 in run_argv /home/user/linux/tools/perf/perf.c:409:2 #11 0x7b0c89 in main /home/user/linux/tools/perf/perf.c:539:3 #12 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)Indirect leak of 32 byte(s) in 1 object(s) allocated from:
#0 0x4f4137 in calloc (/home/user/linux/tools/perf/perf+0x4f4137) #1 0xbe3d56 in zalloc /home/user/linux/tools/lib/perf/../../lib/zalloc.c:8:9 #2 0xbd77e0 in perf_evsel__alloc_id /home/user/linux/tools/lib/perf/evsel.c:365:14 #3 0x8ae201 in perf_session__read_header /home/user/linux/tools/perf/util/header.c:3871:7 #4 0x8ec714 in perf_session__open /home/user/linux/tools/perf/util/session.c:109:6 #5 0x8ebe83 in perf_session__new /home/user/linux/tools/perf/util/session.c:213:10 #6 0x60c6de in cmd_script /home/user/linux/tools/perf/builtin-script.c:3856:12 #7 0x7b2930 in run_builtin /home/user/linux/tools/perf/perf.c:313:11 #8 0x7b120f in handle_internal_command /home/user/linux/tools/perf/perf.c:365:8 #9 0x7b2493 in run_argv /home/user/linux/tools/perf/perf.c:409:2 #10 0x7b0c89 in main /home/user/linux/tools/perf/perf.c:539:3 #11 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)Indirect leak of 7 byte(s) in 1 object(s) allocated from:
#0 0x4b8207 in strdup (/home/user/linux/tools/perf/perf+0x4b8207) #1 0x8b4459 in evlist__set_event_name /home/user/linux/tools/perf/util/header.c:2292:16 #2 0x89d862 in process_event_desc /home/user/linux/tools/perf/util/header.c:2313:3 #3 0x8af319 in perf_file_section__process /home/user/linux/tools/perf/util/header.c:3651:9 #4 0x8aa6e9 in perf_header__process_sections /home/user/linux/tools/perf/util/header.c:3427:9 #5 0x8ae3e7 in perf_session__read_header /home/user/linux/tools/perf/util/header.c:3886:2 #6 0x8ec714 in perf_session__open /home/user/linux/tools/perf/util/session.c:109:6 #7 0x8ebe83 in perf_session__new /home/user/linux/tools/perf/util/session.c:213:10 #8 0x60c6de in cmd_script /home/user/linux/tools/perf/builtin-script.c:3856:12 #9 0x7b2930 in run_builtin /home/user/linux/tools/perf/perf.c:313:11 #10 0x7b120f in handle_internal_command /home/user/linux/tools/perf/perf.c:365:8 #11 0x7b2493 in run_argv /home/user/linux/tools/perf/perf.c:409:2 #12 0x7b0c89 in main /home/user/linux/tools/perf/perf.c:539:3 #13 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)SUMMARY: AddressSanitizer: 3728 byte(s) leaked in 7 allocation(s).
Signed-off-by Riccardo Mancini <[email protected]>--- tools/perf/util/session.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)tools/perf/util/session.c +4
-2@@ -301,8 +301,11 @@ void perf_session__delete(struct perf_session *session)perf_session__release_decomp_events (session);perf_env__exit (&session->header.env);machines__exit (&session->machines); -if (session->data) +if (session->data) { +if (perf_data__is_read (session->data)) +evlist__delete (session->evlist);perf_data__close (session->data); + }free (session); } --2.31.1
Hi,
thank you both for your comments.
Quoted 20 lines · Jiri Olsa
Quoted 11 lines · Ian Rogers
Quoted 9 lines · Riccardo Mancini
ASan reports a memory leak caused by evlist not being deleted on exit in perf-report, perf-script and perf-data.
The problem is caused byevlist->sessionnot being deleted, which is allocated inperf_session__read_header, called inperf_session__newifperf_datais in read mode.
In case of write mode, thesession->evlistis filled by the caller. This patch solves the problem by callingevlist__deleteinperf_session__deleteifperf_datais in read mode.ugh, I'm surprised we did not free that.. and can't find in git log we ever did ;-) I briefly check commands using sessions and looks like it's correct
Acked-by Jiri Olsa <[email protected]>Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Acked-by Ian Rogers <[email protected]>It is messy that in read mode the session owns the evlist, but otherwise not. Imo, it'd be nice to make the ownership unconditional.
yep, would be nice
I think the root problem is that perf_session__new has different behaviours depending on perf_data and perf_tool and that it probably does too many things for a __new function.
If we split it into multiple functions and then, say, we create two helpers perf_session__init_read and perf_session__init_write, with the corresponding perf_session__fini_read and perf_session__fini_write, then the conditional ownership won't be a big problem due to having these two cases clearly separated.
What do you think?
Thanks,
Riccardo
Quoted 163 lines
thanks,
jirkaQuoted 158 lines
Thanks,
IanQuoted 153 lines
Changes in v2:
- callevlist__deletefrom withinperf_session__deletev1:
https://lore.kernel.org/lkml/[email protected]/ASan report follows:
$ ./perf script report flamegraph ================================================================= ==227640==ERROR: LeakSanitizer: detected memory leaks<SNIP unrelated>
Indirect leak of 2704 byte(s) in 1 object(s) allocated from:
#00x4f4137in calloc (/home/user/linux/tools/perf/perf+0x4f4137) #10xbe3d56in zalloc/home/user/linux/tools/lib/perf/../../lib/zalloc.c:8:9
#20x7f999einevlist__new/home/user/linux/tools/perf/util/evlist.c:77:26
#30x8ad938inperf_session__read_header/home/user/linux/tools/perf/util/header.c:3797:20
#40x8ec714inperf_session__open/home/user/linux/tools/perf/util/session.c:109:6
#50x8ebe83inperf_session__new/home/user/linux/tools/perf/util/session.c:213:10
#60x60c6deincmd_script/home/user/linux/tools/perf/builtin-script.c:3856:12
#70x7b2930inrun_builtin/home/user/linux/tools/perf/perf.c:313:11#80x7b120finhandle_internal_command/home/user/linux/tools/perf/perf.c:365:8
#90x7b2493inrun_argv/home/user/linux/tools/perf/perf.c:409:2#100x7b0c89in main/home/user/linux/tools/perf/perf.c:539:3#11 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)Indirect leak of 568 byte(s) in 1 object(s) allocated from:
#00x4f4137in calloc (/home/user/linux/tools/perf/perf+0x4f4137) #10xbe3d56in zalloc/home/user/linux/tools/lib/perf/../../lib/zalloc.c:8:9
#20x80ce88inevsel__new_idx/home/user/linux/tools/perf/util/evsel.c:268:24
#30x8aed93inevsel__new/home/user/linux/tools/perf/util/evsel.h:210:9#40x8ae07einperf_session__read_header/home/user/linux/tools/perf/util/header.c:3853:11
#50x8ec714inperf_session__open/home/user/linux/tools/perf/util/session.c:109:6
#60x8ebe83inperf_session__new/home/user/linux/tools/perf/util/session.c:213:10
#70x60c6deincmd_script/home/user/linux/tools/perf/builtin-script.c:3856:12
#80x7b2930inrun_builtin/home/user/linux/tools/perf/perf.c:313:11#90x7b120finhandle_internal_command/home/user/linux/tools/perf/perf.c:365:8
#100x7b2493inrun_argv/home/user/linux/tools/perf/perf.c:409:2#110x7b0c89in main/home/user/linux/tools/perf/perf.c:539:3#12 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)Indirect leak of 264 byte(s) in 1 object(s) allocated from:
#00x4f4137in calloc (/home/user/linux/tools/perf/perf+0x4f4137) #10xbe3d56in zalloc/home/user/linux/tools/lib/perf/../../lib/zalloc.c:8:9
#20xbe3e70inxyarray__new/home/user/linux/tools/lib/perf/xyarray.c:10:23
#30xbd7754inperf_evsel__alloc_id/home/user/linux/tools/lib/perf/evsel.c:361:21
#40x8ae201inperf_session__read_header/home/user/linux/tools/perf/util/header.c:3871:7
#50x8ec714inperf_session__open/home/user/linux/tools/perf/util/session.c:109:6
#60x8ebe83inperf_session__new/home/user/linux/tools/perf/util/session.c:213:10
#70x60c6deincmd_script/home/user/linux/tools/perf/builtin-script.c:3856:12
#80x7b2930inrun_builtin/home/user/linux/tools/perf/perf.c:313:11#90x7b120finhandle_internal_command/home/user/linux/tools/perf/perf.c:365:8
#100x7b2493inrun_argv/home/user/linux/tools/perf/perf.c:409:2#110x7b0c89in main/home/user/linux/tools/perf/perf.c:539:3#12 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)Indirect leak of 32 byte(s) in 1 object(s) allocated from:
#00x4f4137in calloc (/home/user/linux/tools/perf/perf+0x4f4137) #10xbe3d56in zalloc/home/user/linux/tools/lib/perf/../../lib/zalloc.c:8:9
#20xbd77e0inperf_evsel__alloc_id/home/user/linux/tools/lib/perf/evsel.c:365:14
#30x8ae201inperf_session__read_header/home/user/linux/tools/perf/util/header.c:3871:7
#40x8ec714inperf_session__open/home/user/linux/tools/perf/util/session.c:109:6
#50x8ebe83inperf_session__new/home/user/linux/tools/perf/util/session.c:213:10
#60x60c6deincmd_script/home/user/linux/tools/perf/builtin-script.c:3856:12
#70x7b2930inrun_builtin/home/user/linux/tools/perf/perf.c:313:11#80x7b120finhandle_internal_command/home/user/linux/tools/perf/perf.c:365:8
#90x7b2493inrun_argv/home/user/linux/tools/perf/perf.c:409:2#100x7b0c89in main/home/user/linux/tools/perf/perf.c:539:3#11 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)Indirect leak of 7 byte(s) in 1 object(s) allocated from:
#00x4b8207in strdup (/home/user/linux/tools/perf/perf+0x4b8207) #10x8b4459inevlist__set_event_name/home/user/linux/tools/perf/util/header.c:2292:16
#20x89d862inprocess_event_desc/home/user/linux/tools/perf/util/header.c:2313:3
#30x8af319inperf_file_section__process/home/user/linux/tools/perf/util/header.c:3651:9
#40x8aa6e9inperf_header__process_sections/home/user/linux/tools/perf/util/header.c:3427:9
#50x8ae3e7inperf_session__read_header/home/user/linux/tools/perf/util/header.c:3886:2
#60x8ec714inperf_session__open/home/user/linux/tools/perf/util/session.c:109:6
#70x8ebe83inperf_session__new/home/user/linux/tools/perf/util/session.c:213:10
#80x60c6deincmd_script/home/user/linux/tools/perf/builtin-script.c:3856:12
#90x7b2930inrun_builtin/home/user/linux/tools/perf/perf.c:313:11#100x7b120finhandle_internal_command/home/user/linux/tools/perf/perf.c:365:8
#110x7b2493inrun_argv/home/user/linux/tools/perf/perf.c:409:2#120x7b0c89in main/home/user/linux/tools/perf/perf.c:539:3#13 0x7f5260654b74 (/lib64/libc.so.6+0x27b74)SUMMARY: AddressSanitizer: 3728 byte(s) leaked in 7 allocation(s).
Signed-off-by Riccardo Mancini <[email protected]>---
tools/perf/util/session.c | 5 ++++-1 file changed, 4 insertions(+), 1 deletion(-)tools/perf/util/session.c +4
-2@@ -301,8 +301,11 @@ void perf_session__delete(struct perf_session *session) perf_session__release_decomp_events(session); perf_env__exit(&session->header.env); machines__exit(&session->machines); - if (session->data) + if (session->data) { + if (perf_data__is_read(session->data)) + evlist__delete(session->evlist); perf_data__close(session->data); + } free(session); } --2.31.1
Quoted 32 lines · Riccardo Mancini
Hi,
thank you both for your comments.
Quoted 20 lines · Jiri Olsa
Quoted 11 lines · Ian Rogers
Quoted 9 lines · Riccardo Mancini
ASan reports a memory leak caused by evlist not being deleted on exit in perf-report, perf-script and perf-data.
The problem is caused byevlist->sessionnot being deleted, which is allocated inperf_session__read_header, called inperf_session__newifperf_datais in read mode.
In case of write mode, thesession->evlistis filled by the caller. This patch solves the problem by callingevlist__deleteinperf_session__deleteifperf_datais in read mode.ugh, I'm surprised we did not free that.. and can't find in git log we ever did ;-) I briefly check commands using sessions and looks like it's correct
Acked-by Jiri Olsa <[email protected]>Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Acked-by Ian Rogers <[email protected]>It is messy that in read mode the session owns the evlist, but otherwise not. Imo, it'd be nice to make the ownership unconditional.
yep, would be nice
Quoted 9 lines
I think the root problem is that
perf_session__newhas different behaviours depending onperf_dataandperf_tooland that it probably does too many things for a__newfunction.
If we split it into multiple functions and then, say, we create two helpersperf_session__init_readandperf_session__init_write, with the correspondingperf_session__fini_readandperf_session__fini_write, then the conditional ownership won't be a big problem due to having these two cases clearly separated.
What do you think?
yes, interesting idea, let's see how the code looks like ;-)
thanks,
jirka
Em Fri, Jun 25, 2021 at 01:54:03PM +0200, Jiri Olsa escreveu:
Quoted 19 lines · Ian Rogers
Quoted 10 lines · Riccardo Mancini
Quoted 9 lines
ASan reports a memory leak caused by evlist not being deleted on exit in perf-report, perf-script and perf-data.
The problem is caused byevlist->sessionnot being deleted, which is allocated inperf_session__read_header, called inperf_session__newifperf_datais in read mode.
In case of write mode, thesession->evlistis filled by the caller. This patch solves the problem by callingevlist__deleteinperf_session__deleteifperf_datais in read mode.ugh, I'm surprised we did not free that.. and can't find in git log we ever did ;-) I briefly check commands using sessions and looks like it's correct
Acked-by Jiri Olsa <[email protected]>Quoted 1 line
Quoted 6 lines
Quoted 4 lines
Acked-by Ian Rogers <[email protected]>It is messy that in read mode the session owns the evlist, but otherwise not. Imo, it'd be nice to make the ownership unconditional.
yep, would be nice
Thanks, applied.
Riccardo, next time please consider adding a Fixes: tag so that the [email protected] guys can pick this for stable releases.
- Arnaldo