[llvm] r306788 - Rewrite demangle memory handling.

Eric Christopher via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 29 22:38:57 PDT 2017


Author: echristo
Date: Thu Jun 29 22:38:56 2017
New Revision: 306788

URL: http://llvm.org/viewvc/llvm-project?rev=306788&view=rev
Log:
Rewrite demangle memory handling.
The return of itaniumDemangle is allocated with malloc rather than new[]
and so using unique_ptr isn't called for here. As a note for the future
we should rewrite it to do this.

Modified:
    llvm/trunk/tools/llvm-nm/llvm-nm.cpp

Modified: llvm/trunk/tools/llvm-nm/llvm-nm.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-nm/llvm-nm.cpp?rev=306788&r1=306787&r2=306788&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-nm/llvm-nm.cpp (original)
+++ llvm/trunk/tools/llvm-nm/llvm-nm.cpp Thu Jun 29 22:38:56 2017
@@ -672,12 +672,14 @@ static Optional<std::string> demangle(St
     return None;
 
   int Status;
-  std::unique_ptr<char[]> Undecorated(
-      itaniumDemangle(Name.str().c_str(), nullptr, nullptr, &Status));
+  char *Undecorated =
+      itaniumDemangle(Name.str().c_str(), nullptr, nullptr, &Status);
   if (Status != 0)
     return None;
 
-  return std::string(Undecorated.get());
+  std::string S(Undecorated);
+  free(Undecorated);
+  return S;
 }
 
 static bool symbolIsDefined(const NMSymbol &Sym) {




More information about the llvm-commits mailing list