[ELF] Fix stack-use-after-scope after D69592 and 69650
authorFangrui Song <maskray@google.com>
Fri, 8 Nov 2019 19:19:03 +0000 (11:19 -0800)
committerFangrui Song <maskray@google.com>
Fri, 8 Nov 2019 19:21:32 +0000 (11:21 -0800)
lld/ELF/Relocations.cpp

index 98abbe1..a4fc1ff 100644 (file)
@@ -701,7 +701,8 @@ static std::vector<UndefinedDiag> undefs;
 // the reference name ref.
 static bool canSuggestExternCForCXX(StringRef ref, StringRef def) {
   llvm::ItaniumPartialDemangler d;
-  if (d.partialDemangle(def.str().c_str()))
+  std::string name = def.str();
+  if (d.partialDemangle(name.c_str()))
     return false;
   char *buf = d.getFunctionName(nullptr, nullptr);
   if (!buf)
@@ -779,8 +780,9 @@ static const Symbol *getAlternativeSpelling(const Undefined &sym,
   // The reference may be a mangled name while the definition is not. Suggest a
   // missing extern "C".
   if (name.startswith("_Z")) {
+    std::string buf = name.str();
     llvm::ItaniumPartialDemangler d;
-    if (!d.partialDemangle(name.str().c_str()))
+    if (!d.partialDemangle(buf.c_str()))
       if (char *buf = d.getFunctionName(nullptr, nullptr)) {
         const Symbol *s = suggest(buf);
         free(buf);