Skip to content

Fix memory leaks (was reference count checking for thread)

Ian Rogers linux-arm-kernel linux-perf-users lkml 2 versions – Applied

Status from this message: Applied.

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest26 patches 13 repliesApplied
  2. v120 patches 1 replySuperseded

Patches in v2 Applied

#Subject and filesSizeRepliesApplied
1/26perf thread: Remove notion of dead threadstools/perf/builtin-sched.c tools/perf/util/cs-etm.c tools/perf/util/intel-pt.c +3 more+4 -1010 replies
2/26perf thread: Make threads rbtree non-invasivetools/perf/builtin-report.c tools/perf/builtin-trace.c tools/perf/util/machine.c +2 more+73 -411 reply
3/26perf thread: Add accessor functions for threadtools/perf/arch/arm/tests/dwarf-unwind.c tools/perf/arch/arm64/tests/dwarf-unwind.c tools/perf/arch/powerpc/tests/dwarf-unwind.c +42 more+485 -2792 replies
4/26perf maps: Make delete static, always use puttools/perf/tests/maps.c tools/perf/util/machine.c tools/perf/util/maps.c +1 more+11 -41 reply
5/26perf addr_location: Move to its own headertools/perf/util/Build tools/perf/util/addr_location.c tools/perf/util/addr_location.h +2 more+46 -281 reply
6/26perf addr_location: Add init/exit/copy functionstools/perf/builtin-annotate.c tools/perf/builtin-c2c.c tools/perf/builtin-diff.c +32 more+369 -1661 reply
7/26perf thread: Add reference count checkingtools/perf/builtin-sched.c tools/perf/tests/hists_link.c tools/perf/ui/hist.c +5 more+63 -530 replies
8/26perf machine: Make delete_threads part of machine__exittools/perf/tests/code-reading.c tools/perf/tests/dwarf-unwind.c tools/perf/tests/mmap-thread-lookup.c +3 more+1 -100 replies
9/26perf report: Avoid thread leaktools/perf/builtin-report.c+1 -00 replies
10/26perf header: Ensure bitmaps are freedtools/perf/util/header.c+10 -20 replies
11/26perf stat: Avoid evlist leaktools/perf/builtin-stat.c+1 -00 replies
12/26perf intel-pt: Fix missed put and leaktools/perf/util/intel-pt.c+2 -00 replies
13/26perf evlist: Free stats in all evlist destructiontools/perf/util/evlist.c tools/perf/util/python.c+6 -00 replies
14/26perf python: Avoid 2 leak sanitizer issuestools/perf/util/scripting-engines/trace-event-python.c+5 -10 replies
15/26perf jit: Fix two thread leakstools/perf/util/jitdump.c+2 -00 replies
16/26perf symbol-elf: Correct holding a referencetools/perf/util/symbol-elf.c+2 -20 replies
17/26perf maps: Fix overlapping memory leaktools/perf/util/maps.c+1 -00 replies
18/26perf machine: Fix leak of kernel dsotools/perf/util/machine.c+2 -10 replies
19/26perf machine: Don't leak module mapstools/perf/util/machine.c+3 -30 replies
20/26perf map/maps/thread: Changes to reference countingtools/perf/util/callchain.c tools/perf/util/event.c tools/perf/util/hist.c +1 more+46 -200 replies
21/26perf annotate: Fix parse_objdump_line memory leaktools/perf/util/annotate.c+2 -10 replies
22/26perf top: Add exit routine for main threadtools/perf/builtin-top.c+10 -10 replies
23/26perf header: Avoid out-of-bounds readtools/perf/util/header.c+1 -10 replies
24/26perf callchain: Use pthread keys for tls callchain_cursortools/perf/builtin-c2c.c tools/perf/builtin-script.c tools/perf/util/callchain.c +4 more+86 -351 reply
25/26perf srcline: Change free_srcline to zfree_srclinetools/perf/builtin-diff.c tools/perf/util/annotate.c tools/perf/util/block-info.c +4 more+20 -150 replies
26/26perf hist: Fix srcline memory leaktools/perf/util/hist.c+1 -16 replies

Reviews trailers per patch

1 of 26 patches has a Reviewed-by or Acked-by.

PatchIan Rogers
1/26
2/26
3/26
4/26
5/26
6/26
7/26
8/26
9/26
10/26
11/26
12/26
13/26
14/26
15/26
16/26
17/26
18/26
19/26
20/26
21/26
22/26
23/26
24/26
25/26
26/26A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 00/26] Fix memory leaks (was reference count checking for thread)

Use leak sanitizer and reference count checking to fix outstanding memory leaks in "perf top" or those discovered in "perf test". Also fix address sanitizer issues discovered.

Add reference count checking to thread after first refactoring bits of the code, such as making the thread red-black tree non-invasive (so the thread it references is easier to reference count, rather than having 3 potential references). Part of this refactoring also removes the dead thread list because if we held a reference here the threads would never die and anything else has questionable correctness.

addr_location is made into its own C/header file to capture the init, exit and copy code.

Refactor and change callchain_cursor to come from a pthread key so that a destructor can run on pthreads exiting.

Fix additional outstanding memory leak and reference count issues to the point that "perf test" compiled with address sanitizer but without libtraceevent passes all but one test - libtraceevent reports leaks within its own code, most likely as it isn't compiled with sanitizers. The remaining failing test is "68: Test dwarf unwind" and that has address sanitizer issues as it uses memcpy to access the stack within the process - we likely want to skip parts of the test with sanitizers enabled.

v2. Include extra fixes for callchain cursor, addr2line and related
"perf top" fixes, as well as the 2 patches in:
https://lore.kernel.org/lkml/[email protected]/

Ian Rogers (26):
perf thread: Remove notion of dead threads
perf thread: Make threads rbtree non-invasive perf thread: Add accessor functions for thread perf maps: Make delete static, always use put perf addr_location: Move to its own header
perf addr_location: Add init/exit/copy functions perf thread: Add reference count checking
perf machine: Make delete_threads part of machine__exit perf report: Avoid thread leak
perf header: Ensure bitmaps are freed
perf stat: Avoid evlist leak
perf intel-pt: Fix missed put and leak
perf evlist: Free stats in all evlist destruction perf python: Avoid 2 leak sanitizer issues
perf jit: Fix two thread leaks
perf symbol-elf: Correct holding a reference perf maps: Fix overlapping memory leak
perf machine: Fix leak of kernel dso
perf machine: Don't leak module maps
perf map/maps/thread: Changes to reference counting perf annotate: Fix parse_objdump_line memory leak perf top: Add exit routine for main thread
perf header: Avoid out-of-bounds read
perf callchain: Use pthread keys for tls callchain_cursor perf srcline: Change free_srcline to zfree_srcline perf hist: Fix srcline memory leak

 tools/perf/arch/arm/tests/dwarf-unwind.c      |   2 +-
 tools/perf/arch/arm64/tests/dwarf-unwind.c    |   2 +-
 tools/perf/arch/powerpc/tests/dwarf-unwind.c  |   2 +-
 tools/perf/arch/x86/tests/dwarf-unwind.c      |   2 +-
 tools/perf/builtin-annotate.c                 |  28 +-
 tools/perf/builtin-c2c.c                      |  22 +-
 tools/perf/builtin-diff.c                     |  20 +-
 tools/perf/builtin-inject.c                   |   4 +-
 tools/perf/builtin-kmem.c                     |  13 +-
 tools/perf/builtin-kwork.c                    |  15 +-
 tools/perf/builtin-mem.c                      |   4 +-
 tools/perf/builtin-report.c                   |  21 +-
 tools/perf/builtin-sched.c                    |  80 ++---
 tools/perf/builtin-script.c                   | 123 ++++----
 tools/perf/builtin-stat.c                     |   1 +
 tools/perf/builtin-timechart.c                |  11 +-
 tools/perf/builtin-top.c                      |  19 +-
 tools/perf/builtin-trace.c                    |  38 ++-
 .../scripts/python/Perf-Trace-Util/Context.c  |   4 +-
 tools/perf/tests/code-reading.c               |   6 +-
 tools/perf/tests/dwarf-unwind.c               |   1 -
 tools/perf/tests/hists_common.c               |   2 +-
 tools/perf/tests/hists_cumulate.c             |  18 +-
 tools/perf/tests/hists_filter.c               |  11 +-
 tools/perf/tests/hists_link.c                 |  20 +-
 tools/perf/tests/hists_output.c               |  12 +-
 tools/perf/tests/maps.c                       |   2 +-
 tools/perf/tests/mmap-thread-lookup.c         |   5 +-
 tools/perf/tests/perf-targz-src-pkg           |   5 +-
 tools/perf/tests/symbols.c                    |   1 -
 tools/perf/tests/thread-maps-share.c          |  13 +-
 tools/perf/trace/beauty/pid.c                 |   4 +-
 tools/perf/ui/browsers/hists.c                |  19 +-
 tools/perf/ui/hist.c                          |   5 +-
 tools/perf/ui/stdio/hist.c                    |   2 +-
 tools/perf/util/Build                         |   1 +
 tools/perf/util/addr_location.c               |  44 +++
 tools/perf/util/addr_location.h               |  31 ++
 tools/perf/util/annotate.c                    |   5 +-
 tools/perf/util/arm-spe.c                     |   4 +-
 tools/perf/util/block-info.c                  |   4 +-
 tools/perf/util/build-id.c                    |   2 +
 tools/perf/util/callchain.c                   |  68 +++-
 tools/perf/util/callchain.h                   |   4 +-
 tools/perf/util/cs-etm.c                      |  28 +-
 tools/perf/util/data-convert-json.c           |  16 +-
 tools/perf/util/db-export.c                   |  30 +-
 tools/perf/util/dlfilter.c                    |  17 +-
 tools/perf/util/event.c                       |  37 +--
 tools/perf/util/evlist.c                      |   2 +
 tools/perf/util/evsel_fprintf.c               |   8 +-
 tools/perf/util/header.c                      |  14 +-
 tools/perf/util/hist.c                        |  59 ++--
 tools/perf/util/intel-bts.c                   |   2 +-
 tools/perf/util/intel-pt.c                    |  88 +++---
 tools/perf/util/jitdump.c                     |  12 +-
 tools/perf/util/machine.c                     | 292 +++++++++---------
 tools/perf/util/map.c                         |   4 +-
 tools/perf/util/maps.c                        |   5 +-
 tools/perf/util/maps.h                        |   9 +-
 tools/perf/util/python.c                      |   4 +
 .../scripting-engines/trace-event-python.c    |  40 ++-
 tools/perf/util/session.c                     |   8 +-
 tools/perf/util/sort.c                        |  12 +-
 tools/perf/util/srcline.c                     |  15 +-
 tools/perf/util/srcline.h                     |   2 +-
 tools/perf/util/symbol-elf.c                  |   4 +-
 tools/perf/util/symbol.h                      |  17 +-
 tools/perf/util/thread-stack.c                |  25 +-
 tools/perf/util/thread.c                      | 222 +++++++------
 tools/perf/util/thread.h                      | 210 ++++++++++++-
 tools/perf/util/unwind-libdw.c                |  27 +-
 tools/perf/util/unwind-libunwind-local.c      |  19 +-
 tools/perf/util/unwind-libunwind.c            |   2 +-
 tools/perf/util/vdso.c                        |   2 +-
 75 files changed, 1210 insertions(+), 722 deletions(-)
 create mode 100644 tools/perf/util/addr_location.c
 create mode 100644 tools/perf/util/addr_location.h
Signature · 1 line
2.41.0.162.gfafddb0af9-goog