CIndex: avoid a dangling pointer issue.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@84413 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/CIndex/CIndex.cpp b/tools/CIndex/CIndex.cpp
index 6015ffd..c262f67 100644
--- a/tools/CIndex/CIndex.cpp
+++ b/tools/CIndex/CIndex.cpp
@@ -268,7 +268,8 @@
 
 class CIndexer : public Indexer {
 public:  
-  explicit CIndexer(Program *prog) : Indexer(*prog), OnlyLocalDecls(false) {}
+  explicit CIndexer(Program *prog, std::string &path)
+    : Indexer(*prog), OnlyLocalDecls(false), ClangPath(path) {}
 
   virtual ~CIndexer() { delete &getProgram(); }
 
@@ -277,17 +278,17 @@
   /// declarations.
   bool getOnlyLocalDecls() const { return OnlyLocalDecls; }
   void setOnlyLocalDecls(bool Local = true) { OnlyLocalDecls = Local; }
-  
+
+  const std::string& getClangPath() { return ClangPath; }
 private:
   bool OnlyLocalDecls;
+  std::string ClangPath;
 };
   
 }
 
 extern "C" {
 
-static const char *clangPath;
-
 CXIndex clang_createIndex() 
 {
   // FIXME: This is a hack to unbreak the MSVC build.
@@ -308,9 +309,7 @@
   // We now have the CIndex directory, locate clang relative to it.
   std::string ClangPath = CIndexDir + "/../bin/clang";
   
-  clangPath = ClangPath.c_str();
-  
-  return new CIndexer(new Program());
+  return new CIndexer(new Program(), ClangPath);
 }
 
 void clang_disposeIndex(CXIndex CIdx)
@@ -345,7 +344,7 @@
 #else
   // Build up the arguments for involing clang.
   std::vector<const char *> argv;
-  argv.push_back(clangPath);
+  argv.push_back(static_cast<CIndexer *>(CIdx)->getClangPath().c_str());
   argv.push_back("-emit-ast");
   argv.push_back(source_filename);
   argv.push_back("-o");