Forráskód Böngészése

Plug a leak in the preprocessing record's handling of inclusion
directives. We had a std::string in an object that was allocated via a
BumpPtrAllocator.


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

Douglas Gregor 15 éve
szülő
commit
4ab829c2a2

+ 4 - 6
include/clang/Lex/PreprocessingRecord.h

@@ -199,7 +199,7 @@ namespace clang {
   private:
   private:
     /// \brief The name of the file that was included, as written in
     /// \brief The name of the file that was included, as written in
     /// the source.
     /// the source.
-    std::string FileName;
+    llvm::StringRef FileName;
 
 
     /// \brief Whether the file name was in quotation marks; otherwise, it was
     /// \brief Whether the file name was in quotation marks; otherwise, it was
     /// in angle brackets.
     /// in angle brackets.
@@ -214,11 +214,9 @@ namespace clang {
     const FileEntry *File;
     const FileEntry *File;
 
 
   public:
   public:
-    explicit InclusionDirective(InclusionKind Kind,
-                                const std::string &FileName, bool InQuotes,
-                                const FileEntry *File, SourceRange Range)
-      : PreprocessingDirective(InclusionDirectiveKind, Range), 
-        FileName(FileName), InQuotes(InQuotes), Kind(Kind), File(File) { }
+    InclusionDirective(PreprocessingRecord &PPRec,
+                       InclusionKind Kind, llvm::StringRef FileName, 
+                       bool InQuotes, const FileEntry *File, SourceRange Range);
     
     
     /// \brief Determine what kind of inclusion directive this is.
     /// \brief Determine what kind of inclusion directive this is.
     InclusionKind getKind() const { return static_cast<InclusionKind>(Kind); }
     InclusionKind getKind() const { return static_cast<InclusionKind>(Kind); }

+ 18 - 2
lib/Lex/PreprocessingRecord.cpp

@@ -21,6 +21,22 @@ using namespace clang;
 
 
 ExternalPreprocessingRecordSource::~ExternalPreprocessingRecordSource() { }
 ExternalPreprocessingRecordSource::~ExternalPreprocessingRecordSource() { }
 
 
+
+InclusionDirective::InclusionDirective(PreprocessingRecord &PPRec,
+                                       InclusionKind Kind, 
+                                       llvm::StringRef FileName, 
+                                       bool InQuotes, const FileEntry *File, 
+                                       SourceRange Range)
+  : PreprocessingDirective(InclusionDirectiveKind, Range), 
+    InQuotes(InQuotes), Kind(Kind), File(File) 
+{ 
+  char *Memory 
+    = (char*)PPRec.Allocate(FileName.size() + 1, llvm::alignOf<char>());
+  memcpy(Memory, FileName.data(), FileName.size());
+  Memory[FileName.size()] = 0;
+  this->FileName = llvm::StringRef(Memory, FileName.size());
+}
+
 void PreprocessingRecord::MaybeLoadPreallocatedEntities() const {
 void PreprocessingRecord::MaybeLoadPreallocatedEntities() const {
   if (!ExternalSource || LoadedPreallocatedEntities)
   if (!ExternalSource || LoadedPreallocatedEntities)
     return;
     return;
@@ -160,7 +176,7 @@ void PreprocessingRecord::InclusionDirective(SourceLocation HashLoc,
   }
   }
   
   
   clang::InclusionDirective *ID
   clang::InclusionDirective *ID
-    = new (*this) clang::InclusionDirective(Kind, FileName, !IsAngled, File, 
-                                            SourceRange(HashLoc, EndLoc));
+    = new (*this) clang::InclusionDirective(*this, Kind, FileName, !IsAngled, 
+                                            File, SourceRange(HashLoc, EndLoc));
   PreprocessedEntities.push_back(ID);
   PreprocessedEntities.push_back(ID);
 }
 }

+ 1 - 1
lib/Serialization/ASTReader.cpp

@@ -1555,7 +1555,7 @@ void ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) {
       InclusionDirective::InclusionKind Kind
       InclusionDirective::InclusionKind Kind
         = static_cast<InclusionDirective::InclusionKind>(Record[5]);
         = static_cast<InclusionDirective::InclusionKind>(Record[5]);
       InclusionDirective *ID
       InclusionDirective *ID
-        = new (PPRec) InclusionDirective(Kind,
+        = new (PPRec) InclusionDirective(PPRec, Kind,
                              llvm::StringRef(BlobStart, Record[3]),
                              llvm::StringRef(BlobStart, Record[3]),
                                          Record[4],
                                          Record[4],
                                          File,
                                          File,