[cfe-commits] r117912 - in /cfe/trunk: include/clang/Lex/PreprocessingRecord.h lib/Lex/PreprocessingRecord.cpp lib/Serialization/ASTReader.cpp

Douglas Gregor dgregor at apple.com
Mon Nov 1 08:03:47 PDT 2010


Author: dgregor
Date: Mon Nov  1 10:03:47 2010
New Revision: 117912

URL: http://llvm.org/viewvc/llvm-project?rev=117912&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/Lex/PreprocessingRecord.h
    cfe/trunk/lib/Lex/PreprocessingRecord.cpp
    cfe/trunk/lib/Serialization/ASTReader.cpp

Modified: cfe/trunk/include/clang/Lex/PreprocessingRecord.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/PreprocessingRecord.h?rev=117912&r1=117911&r2=117912&view=diff
==============================================================================
--- cfe/trunk/include/clang/Lex/PreprocessingRecord.h (original)
+++ cfe/trunk/include/clang/Lex/PreprocessingRecord.h Mon Nov  1 10:03:47 2010
@@ -199,7 +199,7 @@
   private:
     /// \brief The name of the file that was included, as written in
     /// the source.
-    std::string FileName;
+    llvm::StringRef FileName;
 
     /// \brief Whether the file name was in quotation marks; otherwise, it was
     /// in angle brackets.
@@ -214,11 +214,9 @@
     const FileEntry *File;
 
   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.
     InclusionKind getKind() const { return static_cast<InclusionKind>(Kind); }

Modified: cfe/trunk/lib/Lex/PreprocessingRecord.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PreprocessingRecord.cpp?rev=117912&r1=117911&r2=117912&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PreprocessingRecord.cpp (original)
+++ cfe/trunk/lib/Lex/PreprocessingRecord.cpp Mon Nov  1 10:03:47 2010
@@ -21,6 +21,22 @@
 
 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 {
   if (!ExternalSource || LoadedPreallocatedEntities)
     return;
@@ -160,7 +176,7 @@
   }
   
   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);
 }

Modified: cfe/trunk/lib/Serialization/ASTReader.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReader.cpp?rev=117912&r1=117911&r2=117912&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReader.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReader.cpp Mon Nov  1 10:03:47 2010
@@ -1555,7 +1555,7 @@
       InclusionDirective::InclusionKind Kind
         = static_cast<InclusionDirective::InclusionKind>(Record[5]);
       InclusionDirective *ID
-        = new (PPRec) InclusionDirective(Kind,
+        = new (PPRec) InclusionDirective(PPRec, Kind,
                              llvm::StringRef(BlobStart, Record[3]),
                                          Record[4],
                                          File,





More information about the cfe-commits mailing list