From: Daniel Dunbar Date: Sun, 18 Jul 2010 21:16:15 +0000 (+0000) Subject: Driver: Fix a possible use after free. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a001c1ce5fcb669624a5b8e50d0a629d673da901;p=clang 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 bb578b516c..89bc7436a8 100644 --- a/include/clang/Driver/Driver.h +++ b/include/clang/Driver/Driver.h @@ -167,8 +167,8 @@ public: 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 f423d4e3b9..6e6dab1088 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1489,7 +1489,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, 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 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, 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 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA, 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,