perf: fix several memory leaks reported by ASan on perf-test
Status from this message: Thanks, applied.
Get series with b4
b4 am [email protected]Versions newest first
Patches in v1 Applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/20 | perf nsinfo: fix refcountingtools/ tools/ tools/ | +8 | 7 replies | |
| 2/20 | perf env: fix sibling_dies memory leaktools/ | +1 | 2 replies | |
| 3/20 | perf test: session_topology: delete session->evlisttools/ | +1 | 1 reply | |
| 4/20 | perf test: event_update: fix memory leak of evlisttools/ | +1 | 1 reply | |
| 5/20 | perf test: event_update: fix memory leak of unittools/ | +3 | 1 reply | |
| 6/20 | perf dso: fix memory leak in dso__new_maptools/ | +3 | 2 replies | |
| 7/20 | perf test: maps__merge_in: fix memory leak of mapstools/ | +2 | 1 reply | |
| 8/20 | perf env: fix memory leak of cpu_pmu_capstools/ | +1 | 1 reply | |
| 9/20 | perf report: free generated help strings for sort optiontools/ tools/ tools/ | +24 | 1 reply | |
| 10/20 | perf inject: close inject.outputtools/ | +6 | 1 reply | |
| 11/20 | perf session: cleanup trace_eventtools/ | +1 | 1 reply | |
| 12/20 | perf script: release zstd datatools/ | +1 | 1 reply | |
| 13/20 | perf script: fix memory leaks in perf_scripttools/ | +7 | 1 reply | |
| 14/20 | perf util/lzma: close lzma streamtools/ | +5 | 1 reply | |
| 15/20 | perf trace: free malloc'd trace fields on exittools/ | +16 | 1 reply | |
| 16/20 | perf trace: free syscall->arg_fmttools/ | +15 | 1 reply | |
| 17/20 | perf trace: free syscall tp fields in evsel->privtools/ | +16 | 1 reply | |
| 18/20 | perf trace: free strings in trace__parse_events_optiontools/ | +3 | 1 reply | |
| 19/20 | perf test: bpf: free obj_buftools/ | +1 | 2 replies | |
| 20/20 | perf util/probe-file: delete namelist on error in del_eventstools/ | +2 | 1 reply |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 00/20] perf: fix several memory leaks reported by ASan on perf-test
This patchset fixes several memory leaks found using ASan on perf-test. After this patch, all memory leaks in perf-test that were found on my machine are fixed.
This does not mean that there are no longer memory leaks in perf (just running perf report or perf top raises a few), but that now it is possible to run the perf tests with ASan to catch future memory errors.
While many of these leaks have little to no effect on the daily use of perf (some were inside the test itself, other were just a missing cleanup on exit), other were (slightly) more serious, namely:
- nsinfo refcounting was broken since it was not decreased when a reference was replaced, causing many nsinfos to never being deallocated.
- dso__new_map refcounting was wrong, missing a __put
- lzma stream was never closed
Below are the results of perf-test before and after this patchset. Only failed and skipped tests are reported for brevity.
The perf binary has been compiled using
make DEBUG=1 EXTRA_CFLAGS='-fno-omit-frame-pointer -fsanitize=address' compilation using clang shows same results.
Tests are run on my laptop:
Intel(R) Core(TM) i7-5500U CPU @ 2.40GHz (2 cores + hyperthreading) Fedora 34 w/ kernel 5.12.14-300.fc34.x86_64
Before this patchset:
1: vmlinux symtab matches kallsyms : FAILED! 19: 'import perf' in python : FAILED! 23.1: Read Only Watchpoint : Skip (missing hardware support) 31: Lookup mmap thread : FAILED! 41: Session topology : FAILED! 42.1: Basic BPF filtering : FAILED! 42.2: BPF pinning : Skip 42.3: BPF prologue generation : Skip 49: Synthesize attr update : FAILED! 58: builtin clang support : Skip (not compiled in) 63: Test libpfm4 support : Skip (not compiled in) 65: maps__merge_in : FAILED! 73: DWARF unwind : FAILED! 78: build id cache operations : FAILED! 82: Use vfs_getname probe to get syscall args filenames : FAILED! 83: Zstd perf.data compression/decompression : FAILED! 86: perf stat --bpf-counters test : Skip
87: Check Arm CoreSight trace data recording and synthesized samples: Skip
88: Check open filename arg using perf trace + vfs_getname : FAILED!
After this patchset:
19: 'import perf' in python : FAILED! 23.1: Read Only Watchpoint : Skip (missing hardware support) 58: builtin clang support : Skip (not compiled in) 63: Test libpfm4 support : Skip (not compiled in) 73: DWARF unwind : FAILED! 86: perf stat --bpf-counters test : Skip
87: Check Arm CoreSight trace data recording and synthesized samples: Skip
After this patchset, without ASan:
23.1: Read Only Watchpoint : Skip (missing hardware support) 58: builtin clang support : Skip (not compiled in) 63: Test libpfm4 support : Skip (not compiled in) 86: perf stat --bpf-counters test : Skip
87: Check Arm CoreSight trace data recording and synthesized samples: Skip
The two failing tests are false positives and can be skipped:
- "19: 'import perf' in python" fails since there are memory leaks inside the python library.
- "73: DWARF unwind" fails due to stack buffer underflow, since it's unwinding the stack.
Riccardo
Riccardo Mancini (20):
perf nsinfo: fix refcounting
perf env: fix sibling_dies memory leak
perf test: session_topology: delete session->evlist perf test: event_update: fix memory leak of evlist perf test: event_update: fix memory leak of unit perf dso: fix memory leak in dso__new_map
perf test: maps__merge_in: fix memory leak of maps perf env: fix memory leak of cpu_pmu_caps
perf report: free generated help strings for sort option perf inject: close inject.output
perf session: cleanup trace_event
perf script: release zstd data
perf script: fix memory leaks in perf_script
perf util/lzma: close lzma stream
perf trace: free malloc'd trace fields on exit perf trace: free syscall->arg_fmt
perf trace: free syscall tp fields in evsel->priv perf trace: free strings in trace__parse_events_option perf test: bpf: free obj_buf
perf util/probe-file: delete namelist on error in del_events
tools/perf/builtin-inject.c | 13 ++++++--- tools/perf/builtin-report.c | 33 ++++++++++++++------- tools/perf/builtin-script.c | 8 ++++++ tools/perf/builtin-trace.c | 51 +++++++++++++++++++++++++++++++-- tools/perf/tests/bpf.c | 1 + tools/perf/tests/event_update.c | 6 ++-- tools/perf/tests/maps.c | 2 ++ tools/perf/tests/topology.c | 1 + tools/perf/util/dso.c | 4 ++- tools/perf/util/env.c | 2 ++ tools/perf/util/lzma.c | 8 ++++-- tools/perf/util/map.c | 2 ++ tools/perf/util/probe-event.c | 4 ++- tools/perf/util/probe-file.c | 4 +-- tools/perf/util/session.c | 1 + tools/perf/util/sort.c | 2 +- tools/perf/util/sort.h | 2 +- 17 files changed, 116 insertions(+), 28 deletions(-)
Signature · 1 line
2.31.1