diff options
| author | Douglas Gregor <dgregor@apple.com> | 2010-11-01 15:03:47 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2010-11-01 15:03:47 +0000 |
| commit | f09b6c9c85a7fd8b5b999c1ce4ae1766c2565e0b (patch) | |
| tree | ecf70f92fb25327e2d0c399cfaf83e3081caf815 | |
| parent | 1614597873fa80a8d56d42ab20230ca260daa448 (diff) | |
| download | bcm5719-llvm-f09b6c9c85a7fd8b5b999c1ce4ae1766c2565e0b.tar.gz bcm5719-llvm-f09b6c9c85a7fd8b5b999c1ce4ae1766c2565e0b.zip | |
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.
llvm-svn: 117912
| -rw-r--r-- | clang/include/clang/Lex/PreprocessingRecord.h | 10 | ||||
| -rw-r--r-- | clang/lib/Lex/PreprocessingRecord.cpp | 20 | ||||
| -rw-r--r-- | clang/lib/Serialization/ASTReader.cpp | 2 |
3 files changed, 23 insertions, 9 deletions
diff --git a/clang/include/clang/Lex/PreprocessingRecord.h b/clang/include/clang/Lex/PreprocessingRecord.h index 0c5b7bc37f1..69a2f18035b 100644 --- a/clang/include/clang/Lex/PreprocessingRecord.h +++ b/clang/include/clang/Lex/PreprocessingRecord.h @@ -199,7 +199,7 @@ namespace clang { 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 @@ namespace clang { 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); } diff --git a/clang/lib/Lex/PreprocessingRecord.cpp b/clang/lib/Lex/PreprocessingRecord.cpp index 34421779c93..f6036ef779c 100644 --- a/clang/lib/Lex/PreprocessingRecord.cpp +++ b/clang/lib/Lex/PreprocessingRecord.cpp @@ -21,6 +21,22 @@ using namespace clang; 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 @@ void PreprocessingRecord::InclusionDirective(SourceLocation HashLoc, } 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); } diff --git a/clang/lib/Serialization/ASTReader.cpp b/clang/lib/Serialization/ASTReader.cpp index 22d3cbc68f7..5c947bc6395 100644 --- a/clang/lib/Serialization/ASTReader.cpp +++ b/clang/lib/Serialization/ASTReader.cpp @@ -1555,7 +1555,7 @@ void ASTReader::ReadMacroRecord(PerFileData &F, uint64_t Offset) { 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, |

