Driver: Fix a possible use after free.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@108659 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h
index bb578b5..89bc743 100644
--- a/include/clang/Driver/Driver.h
+++ b/include/clang/Driver/Driver.h
@@ -167,8 +167,8 @@
void setTitle(std::string Value) { DriverTitle = Value; }
/// \brief Get the path to the main clang executable.
- std::string getClangProgramPath() const {
- return ClangExecutable;
+ const char *getClangProgramPath() const {
+ return ClangExecutable.c_str();
}
/// @}
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index f423d4e..6e6dab1 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -1489,7 +1489,7 @@
Args.AddAllArgs(CmdArgs, options::OPT_undef);
- std::string Exec = getToolChain().getDriver().getClangProgramPath();
+ const char *Exec = getToolChain().getDriver().getClangProgramPath();
// Optionally embed the -cc1 level arguments into the debug info, for build
// analysis.
@@ -1509,7 +1509,7 @@
CmdArgs.push_back(Args.MakeArgString(Flags.str()));
}
- Dest.addCommand(new Command(JA, *this, Exec.c_str(), CmdArgs));
+ Dest.addCommand(new Command(JA, *this, Exec, CmdArgs));
// Explicitly warn that these options are unsupported, even though
// we are allowing compilation to continue.
@@ -1588,8 +1588,8 @@
CmdArgs.push_back(Input.getFilename());
}
- std::string Exec = getToolChain().getDriver().getClangProgramPath();
- Dest.addCommand(new Command(JA, *this, Exec.c_str(), CmdArgs));
+ const char *Exec = getToolChain().getDriver().getClangProgramPath();
+ Dest.addCommand(new Command(JA, *this, Exec, CmdArgs));
}
void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA,