Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf record: Fix memory leak in vDSO found using ASAN
I got several memory leak reports from Asan with a simple command. It was because VDSO is not released due to the refcount. Like in __dsos_addnew_id(), it should put the refcount after adding to the list. $ perf record true [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.030 MB perf.data (10 samples) ] ================================================================= ==692599==ERROR: LeakSanitizer: detected memory leaks Direct leak of 439 byte(s) in 1 object(s) allocated from: #0 0x7fea52341037 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154 jwrdegoede#1 0x559bce4aa8ee in dso__new_id util/dso.c:1256 jwrdegoede#2 0x559bce59245a in __machine__addnew_vdso util/vdso.c:132 jwrdegoede#3 0x559bce59245a in machine__findnew_vdso util/vdso.c:347 jwrdegoede#4 0x559bce50826c in map__new util/map.c:175 jwrdegoede#5 0x559bce503c92 in machine__process_mmap2_event util/machine.c:1787 jwrdegoede#6 0x559bce512f6b in machines__deliver_event util/session.c:1481 linux-sunxi#7 0x559bce515107 in perf_session__deliver_event util/session.c:1551 linux-sunxi#8 0x559bce51d4d2 in do_flush util/ordered-events.c:244 linux-sunxi#9 0x559bce51d4d2 in __ordered_events__flush util/ordered-events.c:323 linux-sunxi#10 0x559bce519bea in __perf_session__process_events util/session.c:2268 linux-sunxi#11 0x559bce519bea in perf_session__process_events util/session.c:2297 linux-sunxi#12 0x559bce2e7a52 in process_buildids /home/namhyung/project/linux/tools/perf/builtin-record.c:1017 linux-sunxi#13 0x559bce2e7a52 in record__finish_output /home/namhyung/project/linux/tools/perf/builtin-record.c:1234 linux-sunxi#14 0x559bce2ed4f6 in __cmd_record /home/namhyung/project/linux/tools/perf/builtin-record.c:2026 linux-sunxi#15 0x559bce2ed4f6 in cmd_record /home/namhyung/project/linux/tools/perf/builtin-record.c:2858 linux-sunxi#16 0x559bce422db4 in run_builtin /home/namhyung/project/linux/tools/perf/perf.c:313 linux-sunxi#17 0x559bce2acac8 in handle_internal_command /home/namhyung/project/linux/tools/perf/perf.c:365 linux-sunxi#18 0x559bce2acac8 in run_argv /home/namhyung/project/linux/tools/perf/perf.c:409 linux-sunxi#19 0x559bce2acac8 in main /home/namhyung/project/linux/tools/perf/perf.c:539 linux-sunxi#20 0x7fea51e76d09 in __libc_start_main ../csu/libc-start.c:308 Indirect leak of 32 byte(s) in 1 object(s) allocated from: #0 0x7fea52341037 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154 jwrdegoede#1 0x559bce520907 in nsinfo__copy util/namespaces.c:169 jwrdegoede#2 0x559bce50821b in map__new util/map.c:168 jwrdegoede#3 0x559bce503c92 in machine__process_mmap2_event util/machine.c:1787 jwrdegoede#4 0x559bce512f6b in machines__deliver_event util/session.c:1481 jwrdegoede#5 0x559bce515107 in perf_session__deliver_event util/session.c:1551 jwrdegoede#6 0x559bce51d4d2 in do_flush util/ordered-events.c:244 linux-sunxi#7 0x559bce51d4d2 in __ordered_events__flush util/ordered-events.c:323 linux-sunxi#8 0x559bce519bea in __perf_session__process_events util/session.c:2268 linux-sunxi#9 0x559bce519bea in perf_session__process_events util/session.c:2297 linux-sunxi#10 0x559bce2e7a52 in process_buildids /home/namhyung/project/linux/tools/perf/builtin-record.c:1017 linux-sunxi#11 0x559bce2e7a52 in record__finish_output /home/namhyung/project/linux/tools/perf/builtin-record.c:1234 linux-sunxi#12 0x559bce2ed4f6 in __cmd_record /home/namhyung/project/linux/tools/perf/builtin-record.c:2026 linux-sunxi#13 0x559bce2ed4f6 in cmd_record /home/namhyung/project/linux/tools/perf/builtin-record.c:2858 linux-sunxi#14 0x559bce422db4 in run_builtin /home/namhyung/project/linux/tools/perf/perf.c:313 linux-sunxi#15 0x559bce2acac8 in handle_internal_command /home/namhyung/project/linux/tools/perf/perf.c:365 linux-sunxi#16 0x559bce2acac8 in run_argv /home/namhyung/project/linux/tools/perf/perf.c:409 linux-sunxi#17 0x559bce2acac8 in main /home/namhyung/project/linux/tools/perf/perf.c:539 linux-sunxi#18 0x7fea51e76d09 in __libc_start_main ../csu/libc-start.c:308 SUMMARY: AddressSanitizer: 471 byte(s) leaked in 2 allocation(s). Signed-off-by: Namhyung Kim <namhyung@kernel.org> Acked-by: Jiri Olsa <jolsa@redhat.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Peter Zijlstra <peterz@infradead.org> Link: http://lore.kernel.org/lkml/20210315045641.700430-1-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
- Loading branch information