[Lldb-commits] [lldb] a2cd6d0 - [lldb] Fix demangler leaks in the DWARF AST parser

Fangrui Song via lldb-commits lldb-commits at lists.llvm.org
Mon Apr 19 16:37:02 PDT 2021


Author: Fangrui Song
Date: 2021-04-19T16:36:54-07:00
New Revision: a2cd6d07691a645bfb8fb5eeeba2eb5970312c7f

URL: https://github.com/llvm/llvm-project/commit/a2cd6d07691a645bfb8fb5eeeba2eb5970312c7f
DIFF: https://github.com/llvm/llvm-project/commit/a2cd6d07691a645bfb8fb5eeeba2eb5970312c7f.diff

LOG: [lldb] Fix demangler leaks in the DWARF AST parser

This fixes 6 check-lldb-shell failures in a `-DLLVM_USE_SANITIZER=Leaks` build.

Differential Revision: https://reviews.llvm.org/D100800

Added: 
    

Modified: 
    lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index b9e10f94bf6cc..c417f8055c882 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -1226,6 +1226,7 @@ TypeSP DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die,
       }
 
       if (!function_decl) {
+        char *name_buf = nullptr;
         llvm::StringRef name = attrs.name.GetStringRef();
 
         // We currently generate function templates with template parameters in
@@ -1233,8 +1234,10 @@ TypeSP DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die,
         // we want to strip these from the name when creating the AST.
         if (attrs.mangled_name) {
           llvm::ItaniumPartialDemangler D;
-          if (!D.partialDemangle(attrs.mangled_name))
-            name = D.getFunctionBaseName(nullptr, nullptr);
+          if (!D.partialDemangle(attrs.mangled_name)) {
+            name_buf = D.getFunctionBaseName(nullptr, nullptr);
+            name = name_buf;
+          }
         }
 
         // We just have a function that isn't part of a class
@@ -1243,6 +1246,7 @@ TypeSP DWARFASTParserClang::ParseSubroutine(const DWARFDIE &die,
                                       : containing_decl_ctx,
             GetOwningClangModule(die), name, clang_type, attrs.storage,
             attrs.is_inline);
+        std::free(name_buf);
 
         if (has_template_params) {
           TypeSystemClang::TemplateParameterInfos template_param_infos;


        


More information about the lldb-commits mailing list