linux-stable/tools/perf
Arnaldo Carvalho de Melo 7962ef1365 perf trace: Really free the evsel->priv area
In 3cb4d5e00e ("perf trace: Free syscall tp fields in
evsel->priv") it only was freeing if strcmp(evsel->tp_format->system,
"syscalls") returned zero, while the corresponding initialization of
evsel->priv was being performed if it was _not_ zero, i.e. if the tp
system wasn't 'syscalls'.

Just stop looking for that and free it if evsel->priv was set, which
should be equivalent.

Also use the pre-existing evsel_trace__delete() function.

This resolves these leaks, detected with:

  $ make EXTRA_CFLAGS="-fsanitize=address" BUILD_BPF_SKEL=1 CORESIGHT=1 O=/tmp/build/perf-tools-next -C tools/perf install-bin

  =================================================================
  ==481565==ERROR: LeakSanitizer: detected memory leaks

  Direct leak of 40 byte(s) in 1 object(s) allocated from:
      #0 0x7f7343cba097 in calloc (/lib64/libasan.so.8+0xba097)
      #1 0x987966 in zalloc (/home/acme/bin/perf+0x987966)
      #2 0x52f9b9 in evsel_trace__new /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:307
      #3 0x52f9b9 in evsel__syscall_tp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:333
      #4 0x52f9b9 in evsel__init_raw_syscall_tp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:458
      #5 0x52f9b9 in perf_evsel__raw_syscall_newtp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:480
      #6 0x540e8b in trace__add_syscall_newtp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3212
      #7 0x540e8b in trace__run /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3891
      #8 0x540e8b in cmd_trace /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:5156
      #9 0x5ef262 in run_builtin /home/acme/git/perf-tools-next/tools/perf/perf.c:323
      #10 0x4196da in handle_internal_command /home/acme/git/perf-tools-next/tools/perf/perf.c:377
      #11 0x4196da in run_argv /home/acme/git/perf-tools-next/tools/perf/perf.c:421
      #12 0x4196da in main /home/acme/git/perf-tools-next/tools/perf/perf.c:537
      #13 0x7f7342c4a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)

  Direct leak of 40 byte(s) in 1 object(s) allocated from:
      #0 0x7f7343cba097 in calloc (/lib64/libasan.so.8+0xba097)
      #1 0x987966 in zalloc (/home/acme/bin/perf+0x987966)
      #2 0x52f9b9 in evsel_trace__new /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:307
      #3 0x52f9b9 in evsel__syscall_tp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:333
      #4 0x52f9b9 in evsel__init_raw_syscall_tp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:458
      #5 0x52f9b9 in perf_evsel__raw_syscall_newtp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:480
      #6 0x540dd1 in trace__add_syscall_newtp /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3205
      #7 0x540dd1 in trace__run /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:3891
      #8 0x540dd1 in cmd_trace /home/acme/git/perf-tools-next/tools/perf/builtin-trace.c:5156
      #9 0x5ef262 in run_builtin /home/acme/git/perf-tools-next/tools/perf/perf.c:323
      #10 0x4196da in handle_internal_command /home/acme/git/perf-tools-next/tools/perf/perf.c:377
      #11 0x4196da in run_argv /home/acme/git/perf-tools-next/tools/perf/perf.c:421
      #12 0x4196da in main /home/acme/git/perf-tools-next/tools/perf/perf.c:537
      #13 0x7f7342c4a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)

  SUMMARY: AddressSanitizer: 80 byte(s) leaked in 2 allocation(s).
  [root@quaco ~]#

With this we plug all leaks with "perf trace sleep 1".

Fixes: 3cb4d5e00e ("perf trace: Free syscall tp fields in evsel->priv")
Acked-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Link: https://lore.kernel.org/lkml/20230719202951.534582-5-acme@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2023-07-20 11:29:50 -03:00
..
Documentation perf lock contention: Add --output option 2023-07-01 10:48:48 -07:00
arch tools headers UAPI: Sync files changed by new cachestat syscall with the kernel sources 2023-07-11 11:41:15 -03:00
bench perf bench sched messaging: Free contexts on exit 2023-06-12 18:18:14 -03:00
dlfilters perf tools: Fix usage of the verbose variable 2022-12-20 15:16:33 -03:00
examples/bpf perf trace: Remove unused bpf map 'syscalls' 2022-11-23 10:30:00 -03:00
include/perf perf bpf: Remove now unused BPF headers 2022-11-04 11:41:48 -03:00
jvmti
pmu-events perf vendor events amd: Fix large metrics 2023-07-11 11:50:39 -03:00
python
scripts perf python scripting: Get rid of unused import in arm-cs-trace-disasm 2023-06-13 23:40:33 -03:00
tests perf test task_exit: No need for a cycles event to check if we get an PERF_RECORD_EXIT 2023-07-17 10:27:44 -03:00
trace perf beauty: Update copy of linux/socket.h with the kernel sources 2023-07-14 09:59:56 -03:00
ui perf annotation: Switch lock from a mutex to a sharded_mutex 2023-06-20 17:04:21 -07:00
util perf thread: Allow tools to register a thread->priv destructor 2023-07-20 11:22:46 -03:00
.gitignore perf jevents: Run metric_test.py at compile-time 2023-02-03 17:11:39 -03:00
Build perf script: Fix Python support when no libtraceevent 2023-03-15 10:27:07 -03:00
CREDITS
MANIFEST tools lib traceevent: Remove libtraceevent 2022-12-14 11:16:12 -03:00
Makefile perf tools: Use "grep -E" instead of "egrep" 2022-12-14 15:28:19 -03:00
Makefile.config perf build: Fix library not found error when using CSLIBS 2023-07-11 11:46:35 -03:00
Makefile.perf perf: Replace deprecated -target with --target= for Clang 2023-06-27 12:13:22 -07:00
builtin-annotate.c perf addr_location: Add init/exit/copy functions 2023-06-12 15:57:53 -03:00
builtin-bench.c perf bench: Add missing setlocale() call to allow usage of %'d style formatting 2023-06-05 10:36:58 -03:00
builtin-buildid-cache.c
builtin-buildid-list.c perf util: Move input_name to util 2023-04-10 19:21:31 -03:00
builtin-c2c.c perf callchain: Use pthread keys for tls callchain_cursor 2023-06-12 15:57:54 -03:00
builtin-config.c perf path: Make mkpath thread safe, remove 16384 bytes from .bss 2023-05-28 10:24:14 -03:00
builtin-daemon.c perf tools: Add missing else to cmd_daemon subcommand condition 2023-06-27 12:09:44 -07:00
builtin-data.c perf util: Move input_name to util 2023-04-10 19:21:31 -03:00
builtin-diff.c perf srcline: Optimize comparision against SRCLINE_UNKNOWN 2023-06-12 18:17:00 -03:00
builtin-evlist.c perf util: Move input_name to util 2023-04-10 19:21:31 -03:00
builtin-ftrace.c perf tools fixes for v6.4: 2nd batch 2023-05-31 15:31:56 -03:00
builtin-help.c perf path: Make mkpath thread safe, remove 16384 bytes from .bss 2023-05-28 10:24:14 -03:00
builtin-inject.c perf inject: Lazily allocate guest_event event_buf 2023-06-12 18:18:14 -03:00
builtin-kallsyms.c perf symbol: Remove now unused symbol_conf.sort_by_name 2023-06-23 21:48:49 -07:00
builtin-kmem.c perf callchain: Use pthread keys for tls callchain_cursor 2023-06-12 15:57:54 -03:00
builtin-kvm.c perf evsel: Introduce evsel__name_is() method to check if the evsel name is equal to a given string 2023-04-24 14:28:11 -03:00
builtin-kwork.c perf callchain: Use pthread keys for tls callchain_cursor 2023-06-12 15:57:54 -03:00
builtin-list.c perf list: Check arguments to show libpfm4 events 2023-06-12 15:57:53 -03:00
builtin-lock.c perf lock contention: Add --output option 2023-07-01 10:48:48 -07:00
builtin-mem.c perf addr_location: Add init/exit/copy functions 2023-06-12 15:57:53 -03:00
builtin-probe.c perf probe: Dynamically allocate params memory 2023-05-28 10:24:02 -03:00
builtin-record.c perf pmus: Remove perf_pmus__has_hybrid 2023-05-27 09:42:38 -03:00
builtin-report.c perf symbol: Remove now unused symbol_conf.sort_by_name 2023-06-23 21:48:49 -07:00
builtin-sched.c perf sched: Avoid large stack allocations 2023-06-12 18:18:14 -03:00
builtin-script.c perf script: Remove some large stack allocations 2023-06-12 18:18:14 -03:00
builtin-stat.c perf stat: Add missing newline in pr_err messages 2023-06-20 15:55:13 -07:00
builtin-timechart.c perf addr_location: Add init/exit/copy functions 2023-06-12 15:57:53 -03:00
builtin-top.c perf annotation: Switch lock from a mutex to a sharded_mutex 2023-06-20 17:04:21 -07:00
builtin-trace.c perf trace: Really free the evsel->priv area 2023-07-20 11:29:50 -03:00
builtin-version.c Revert "perf build: Make BUILD_BPF_SKEL default, rename to NO_BPF_SKEL" 2023-05-06 18:07:37 -03:00
builtin.h perf usage: Move usage strings 2023-04-10 19:20:53 -03:00
check-headers.sh tools headers: Make the difference output easier to read 2023-06-09 10:56:40 -03:00
command-list.txt perf help: Use HAVE_LIBTRACEEVENT to filter out unsupported commands 2023-01-02 11:51:53 -03:00
design.txt
perf-archive.sh
perf-completion.sh perf tools: Fix auto-complete on aarch64 2023-02-08 10:38:10 -03:00
perf-iostat.sh
perf-read-vdso.c
perf-sys.h
perf.c perf util: Move input_name to util 2023-04-10 19:21:31 -03:00
perf.h perf util: Move perf_guest/host declarations 2023-04-10 19:22:05 -03:00