]> granicus.if.org Git - llvm/commitdiff
Rewrite demangle memory handling.
authorEric Christopher <echristo@gmail.com>
Fri, 30 Jun 2017 05:38:56 +0000 (05:38 +0000)
committerEric Christopher <echristo@gmail.com>
Fri, 30 Jun 2017 05:38:56 +0000 (05:38 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306788 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-nm/llvm-nm.cpp

index b25c4775e8d8d8bdc04aa952c876aa48dc15321e..ea47891250f780db6ee70394879c8f657a382125 100644 (file)
@@ -672,12 +672,14 @@ static Optional<std::string> demangle(StringRef Name, bool StripUnderscore) {
     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) {