diff options
author | Ian Rogers <irogers@google.com> | 2023-03-19 20:37:49 -0700 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2023-03-20 12:49:58 -0300 |
commit | c9602aa0469e19a84f9552a146ef87ec5dc7d576 (patch) | |
tree | 202de04dcafc25c149a0470a0d41f3ef88ce3cc4 | |
parent | 96d541699e5c50b1bc2d50c83cd7145994d5f071 (diff) | |
download | linux-stable-c9602aa0469e19a84f9552a146ef87ec5dc7d576.tar.gz linux-stable-c9602aa0469e19a84f9552a146ef87ec5dc7d576.tar.bz2 linux-stable-c9602aa0469e19a84f9552a146ef87ec5dc7d576.zip |
perf symbol: Avoid memory leak from abi::__cxa_demangle
Rather than allocate memory, allow abi::__cxa_demangle to do
that. This avoids a problem where on error NULL was returned
triggering a memory leak.
Fixes: 3b4e4efe88f615f1 ("perf symbol: Add abi::__cxa_demangle C++ demangling support")
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: André Almeida <andrealmeid@collabora.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Darren Hart <dvhart@infradead.org>
Cc: Davidlohr Bueso <dave@stgolabs.net>
Cc: Dmitriy Vyukov <dvyukov@google.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: German Gomez <german.gomez@arm.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Miaoqian Lin <linmq006@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Shunsuke Nakamura <nakamura.shun@fujitsu.com>
Cc: Song Liu <song@kernel.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Stephen Brennan <stephen.s.brennan@oracle.com>
Cc: Steven Rostedt (VMware) <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Cc: Yury Norov <yury.norov@gmail.com>
Link: https://lore.kernel.org/r/20230320033810.980165-2-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/demangle-cxx.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/tools/perf/util/demangle-cxx.cpp b/tools/perf/util/demangle-cxx.cpp index 8708bcafd370..85b706641837 100644 --- a/tools/perf/util/demangle-cxx.cpp +++ b/tools/perf/util/demangle-cxx.cpp @@ -38,11 +38,10 @@ char *cxx_demangle_sym(const char *str, bool params __maybe_unused, return cplus_demangle(str, flags); #elif defined(HAVE_CXA_DEMANGLE_SUPPORT) - size_t len = strlen(str); - char *output = (char*)malloc(len); + char *output; int status; - output = abi::__cxa_demangle(str, output, &len, &status); + output = abi::__cxa_demangle(str, /*output_buffer=*/NULL, /*length=*/NULL, &status); return output; #else return NULL; |