[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260117052849.2205545-6-irogers@google.com>
Date: Fri, 16 Jan 2026 21:28:31 -0800
From: Ian Rogers <irogers@...gle.com>
To: Peter Zijlstra <peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>, Namhyung Kim <namhyung@...nel.org>, Jiri Olsa <jolsa@...nel.org>,
Ian Rogers <irogers@...gle.com>, Adrian Hunter <adrian.hunter@...el.com>,
James Clark <james.clark@...aro.org>, John Garry <john.g.garry@...cle.com>,
Will Deacon <will@...nel.org>, Leo Yan <leo.yan@...ux.dev>, Guo Ren <guoren@...nel.org>,
Paul Walmsley <pjw@...nel.org>, Palmer Dabbelt <palmer@...belt.com>, Albert Ou <aou@...s.berkeley.edu>,
Alexandre Ghiti <alex@...ti.fr>, Shimin Guo <shimin.guo@...dio.com>,
Athira Rajeev <atrajeev@...ux.ibm.com>, Stephen Brennan <stephen.s.brennan@...cle.com>,
Howard Chu <howardchu95@...il.com>, Thomas Falcon <thomas.falcon@...el.com>,
Andi Kleen <ak@...ux.intel.com>, "Dr. David Alan Gilbert" <linux@...blig.org>,
Dmitry Vyukov <dvyukov@...gle.com>,
"Krzysztof Ćopatowski" <krzysztof.m.lopatowski@...il.com>, Chun-Tse Shao <ctshao@...gle.com>,
Aditya Bodkhe <aditya.b1@...ux.ibm.com>, Haibo Xu <haibo1.xu@...el.com>,
Sergei Trofimovich <slyich@...il.com>, linux-kernel@...r.kernel.org,
linux-perf-users@...r.kernel.org, linux-arm-kernel@...ts.infradead.org,
linux-csky@...r.kernel.org, linux-riscv@...ts.infradead.org,
Mark Wielaard <mark@...mp.org>
Subject: [PATCH v1 05/23] perf libdw_addr2line: Fixes to srcline memory allocation
Some irregular stack traces are causing double frees and memory
leaks. Make the code robust by proactively freeing and being more
careful with the memory management of the leaf_srcline.
Fixes: 88c51002d06f ("perf addr2line: Add a libdw implementation")
Signed-off-by: Ian Rogers <irogers@...gle.com>
---
tools/perf/util/libdw.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/tools/perf/util/libdw.c b/tools/perf/util/libdw.c
index e4bfd52bd172..b96c4e0d728f 100644
--- a/tools/perf/util/libdw.c
+++ b/tools/perf/util/libdw.c
@@ -42,16 +42,24 @@ static int libdw_a2l_cb(Dwarf_Die *die, void *_args)
call_srcline = srcline_from_fileline(call_fname, die_get_call_lineno(die));
list_for_each_entry(ilist, &args->node->val, list) {
+ if (args->leaf_srcline == ilist->srcline)
+ args->leaf_srcline_used = false;
+ else if (ilist->srcline != srcline__unknown)
+ free(ilist->srcline);
ilist->srcline = call_srcline;
call_srcline = NULL;
break;
}
- if (call_srcline && call_fname)
+ if (call_srcline && call_srcline != srcline__unknown)
free(call_srcline);
/* Add this symbol to the chain as the leaf. */
- inline_list__append_tail(inline_sym, args->leaf_srcline, args->node);
- args->leaf_srcline_used = true;
+ if (!args->leaf_srcline_used) {
+ inline_list__append_tail(inline_sym, args->leaf_srcline, args->node);
+ args->leaf_srcline_used = true;
+ } else {
+ inline_list__append_tail(inline_sym, strdup(args->leaf_srcline), args->node);
+ }
return 0;
}
--
2.52.0.457.g6b5491de43-goog
Powered by blists - more mailing lists