[compiler-rt] 649004a - Use InernalAlloc in DemangleCXXABI
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 21 16:23:03 PDT 2023
Author: Fangrui Song
Date: 2023-08-21T16:22:58-07:00
New Revision: 649004ae9ea3cff905bbc0b2777ec12056558129
URL: https://github.com/llvm/llvm-project/commit/649004ae9ea3cff905bbc0b2777ec12056558129
DIFF: https://github.com/llvm/llvm-project/commit/649004ae9ea3cff905bbc0b2777ec12056558129.diff
LOG: Use InernalAlloc in DemangleCXXABI
This reverts commit 06c74b5e7367b41e9b4ea3d74c971aace5681fb8.
Tested on AddressSanitizer-arm64-darwin that there is no more failure.
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp
index 1a5e38faea8874..969c642f267595 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cpp
@@ -46,15 +46,20 @@ namespace __sanitizer {
// Attempts to demangle the name via __cxa_demangle from __cxxabiv1.
const char *DemangleCXXABI(const char *name) {
- // FIXME: __cxa_demangle aggressively insists on allocating memory.
+ // __cxa_demangle aggressively insists on allocating memory.
// There's not much we can do about that, short of providing our
// own demangler (libc++abi's implementation could be adapted so that
- // it does not allocate). For now, we just call it anyway, and we leak
- // the returned value.
- if (&__cxxabiv1::__cxa_demangle)
- if (const char *demangled_name =
- __cxxabiv1::__cxa_demangle(name, 0, 0, 0))
- return demangled_name;
+ // it does not allocate). For now, we just call it anyway, and use
+ // InternalAlloc to prevent lsan error.
+ if (&__cxxabiv1::__cxa_demangle) {
+ if (char *demangled_name = __cxxabiv1::__cxa_demangle(name, 0, 0, 0)) {
+ size_t size = internal_strlen(demangled_name) + 1;
+ char *buf = (char *)InternalAlloc(size);
+ internal_memcpy(buf, demangled_name, size);
+ free(demangled_name);
+ return buf;
+ }
+ }
return name;
}
More information about the llvm-commits
mailing list