mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-10-29 05:12:59 +01:00
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: 3b4e4efe88 ("perf symbol: Add abi::__cxa_demangle C++ demangling support")
Signed-off-by: Ian Rogers <[email protected]>
Cc: Adrian Hunter <[email protected]>
Cc: Alexander Shishkin <[email protected]>
Cc: Alexey Bayduraev <[email protected]>
Cc: Andi Kleen <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: André Almeida <[email protected]>
Cc: Andy Shevchenko <[email protected]>
Cc: Darren Hart <[email protected]>
Cc: Davidlohr Bueso <[email protected]>
Cc: Dmitriy Vyukov <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: German Gomez <[email protected]>
Cc: Hao Luo <[email protected]>
Cc: Ian Rogers <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: James Clark <[email protected]>
Cc: Jiri Olsa <[email protected]>
Cc: John Garry <[email protected]>
Cc: Kajol Jain <[email protected]>
Cc: Kan Liang <[email protected]>
Cc: Leo Yan <[email protected]>
Cc: Madhavan Srinivasan <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Masami Hiramatsu <[email protected]>
Cc: Miaoqian Lin <[email protected]>
Cc: Namhyung Kim <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Riccardo Mancini <[email protected]>
Cc: Shunsuke Nakamura <[email protected]>
Cc: Song Liu <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: Stephen Brennan <[email protected]>
Cc: Steven Rostedt (VMware) <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: Thomas Richter <[email protected]>
Cc: Yury Norov <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
50 lines
1.3 KiB
C++
50 lines
1.3 KiB
C++
// SPDX-License-Identifier: GPL-2.0
|
|
#include "demangle-cxx.h"
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <linux/compiler.h>
|
|
|
|
#ifdef HAVE_LIBBFD_SUPPORT
|
|
#define PACKAGE 'perf'
|
|
#include <bfd.h>
|
|
#endif
|
|
|
|
#ifdef HAVE_CXA_DEMANGLE_SUPPORT
|
|
#include <cxxabi.h>
|
|
#endif
|
|
|
|
#if defined(HAVE_LIBBFD_SUPPORT) || defined(HAVE_CPLUS_DEMANGLE_SUPPORT)
|
|
#ifndef DMGL_PARAMS
|
|
#define DMGL_PARAMS (1 << 0) /* Include function args */
|
|
#define DMGL_ANSI (1 << 1) /* Include const, volatile, etc */
|
|
#endif
|
|
#endif
|
|
|
|
/*
|
|
* Demangle C++ function signature
|
|
*
|
|
* Note: caller is responsible for freeing demangled string
|
|
*/
|
|
extern "C"
|
|
char *cxx_demangle_sym(const char *str, bool params __maybe_unused,
|
|
bool modifiers __maybe_unused)
|
|
{
|
|
#ifdef HAVE_LIBBFD_SUPPORT
|
|
int flags = (params ? DMGL_PARAMS : 0) | (modifiers ? DMGL_ANSI : 0);
|
|
|
|
return bfd_demangle(NULL, str, flags);
|
|
#elif defined(HAVE_CPLUS_DEMANGLE_SUPPORT)
|
|
int flags = (params ? DMGL_PARAMS : 0) | (modifiers ? DMGL_ANSI : 0);
|
|
|
|
return cplus_demangle(str, flags);
|
|
#elif defined(HAVE_CXA_DEMANGLE_SUPPORT)
|
|
char *output;
|
|
int status;
|
|
|
|
output = abi::__cxa_demangle(str, /*output_buffer=*/NULL, /*length=*/NULL, &status);
|
|
return output;
|
|
#else
|
|
return NULL;
|
|
#endif
|
|
}
|