]> granicus.if.org Git - clang/commitdiff
Make sure the std::string isn't deallocated prior to use. Many thanks to Eli
authorChad Rosier <mcrosier@apple.com>
Fri, 26 Aug 2011 21:47:20 +0000 (21:47 +0000)
committerChad Rosier <mcrosier@apple.com>
Fri, 26 Aug 2011 21:47:20 +0000 (21:47 +0000)
for catching this.

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

lib/Driver/Driver.cpp

index acdfdc21a2581f6d0c1659459fc5efce8b28a24e..66d2df16e11dbb6c8d71a2e7c104d21833c9950f 100644 (file)
@@ -1336,12 +1336,12 @@ void Driver::BuildJobsForAction(Compilation &C,
 }
 
 // Strip the directory and suffix from BaseInput.
-static const char *getBaseName (const char *BaseInput) {
+static std::string getBaseName (const char *BaseInput) {
   std::pair<StringRef, StringRef> Split = StringRef(BaseInput).rsplit('/');
   if (Split.second != "")
-    return Split.second.split('.').first.str().c_str();
+    return Split.second.split('.').first.str();
   else
-    return Split.first.split('.').first.str().c_str();
+    return Split.first.split('.').first.str();
 }
 
 const char *Driver::GetNamedOutputPath(Compilation &C,
@@ -1364,7 +1364,7 @@ const char *Driver::GetNamedOutputPath(Compilation &C,
   if ((!AtTopLevel && !C.getArgs().hasArg(options::OPT_save_temps)) ||
       CCGenDiagnostics) {
     std::string TmpName =
-      GetTemporaryPath(getBaseName(BaseInput), 
+      GetTemporaryPath(getBaseName(BaseInput).c_str()
                        types::getTypeTempSuffix(JA.getType()));
     return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()));
   }
@@ -1400,7 +1400,7 @@ const char *Driver::GetNamedOutputPath(Compilation &C,
   if (!AtTopLevel && C.getArgs().hasArg(options::OPT_save_temps) &&
       NamedOutput == BaseName) {
     std::string TmpName =
-      GetTemporaryPath(getBaseName(BaseInput),
+      GetTemporaryPath(getBaseName(BaseInput).c_str(),
                        types::getTypeTempSuffix(JA.getType()));
     return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()));
   }