From 2c9f7bd7951af269afe9680746f4c566c3abc769 Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Thu, 8 Jun 2023 16:28:06 -0700 Subject: perf report: Avoid 'parent_thread' thread leak on '--tasks' processing Caught with address sanitizer and reference count checking. Committer notes: The command leading to this leak: # perf record -a sleep 2 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 2.516 MB perf.data (6422 samples) ] # perf report --tasks # pid tid ppid comm 0 0 -1 |swapper 1 1 0 | systemd 1474 1474 1 | systemd 2816 2816 1474 | gjs 2816 2825 2816 | gmain 2816 2831 2816 | gdbus 2816 2861 2816 | JS Helper 2816 2862 2816 | JS Helper 2816 2863 2816 | JS Helper 2816 2864 2816 | JS Helper 2816 2865 2816 | JS Helper 2816 2866 2816 | JS Helper 2816 2867 2816 | JS Helper 2816 2868 2816 | JS Helper 3072 3072 1474 | gsd-printer 3072 3082 3072 | gmain 3072 3083 3072 | gdbus 2600 2600 1474 | gnome-shell 15621 15621 2600 | firefox 15771 15771 15621 | WebExtensions 15771 15872 15771 | TaskCon~ller #6 15771 15873 15771 | TaskCon~ller #7 15771 15778 15771 | IPC I/O Child 15771 15779 15771 | Socket Thread 15771 15780 15771 | HTML5 Parser 15771 15781 15771 | JS Watchdog # When it is going to exit a thread__put(parent_thread) was missed, add it to have ASAN clean. Signed-off-by: Ian Rogers Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Ali Saidi Cc: Andi Kleen Cc: Athira Rajeev Cc: Brian Robbins Cc: Changbin Du Cc: Dmitrii Dolgov <9erthalion6@gmail.com> Cc: Fangrui Song Cc: German Gomez Cc: Ingo Molnar Cc: Ivan Babrou Cc: James Clark Cc: Jing Zhang Cc: Jiri Olsa Cc: John Garry Cc: K Prateek Nayak Cc: Kan Liang Cc: Leo Yan Cc: Liam Howlett Cc: Mark Rutland Cc: Miguel Ojeda Cc: Mike Leach Cc: Namhyung Kim Cc: Naveen N. Rao Cc: Peter Zijlstra Cc: Ravi Bangoria Cc: Sean Christopherson Cc: Steinar H. Gunderson Cc: Suzuki Poulouse Cc: Wenyu Liu Cc: Will Deacon Cc: Yang Jihong Cc: Ye Xingchen Cc: Yuan Can Cc: coresight@lists.linaro.org Cc: linux-arm-kernel@lists.infradead.org Link: https://lore.kernel.org/r/20230608232823.4027869-10-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-report.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tools/perf/builtin-report.c') diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 0b091a8983a5..a31a23af5547 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -839,6 +839,7 @@ static struct task *tasks_list(struct task *task, struct machine *machine) return ERR_PTR(-ENOENT); parent_task = thread__priv(parent_thread); + thread__put(parent_thread); list_add_tail(&task->list, &parent_task->children); return tasks_list(parent_task, machine); } -- cgit