aboutsummaryrefslogtreecommitdiff
path: root/lib/Lex/PreprocessingRecord.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-11-01 15:03:47 +0000
committerDouglas Gregor <dgregor@apple.com>2010-11-01 15:03:47 +0000
commit4ab829c2a229dc20ecb9f35e7337bbfa95bf4026 (patch)
treec349c90f8866912df963e9919e66d299884a555d /lib/Lex/PreprocessingRecord.cpp
parent9dba61a1e46099b77adf15de224aaa16037a7fff (diff)
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
Diffstat (limited to 'lib/Lex/PreprocessingRecord.cpp')
-rw-r--r--lib/Lex/PreprocessingRecord.cpp20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/Lex/PreprocessingRecord.cpp b/lib/Lex/PreprocessingRecord.cpp
index 34421779c9..f6036ef779 100644
--- a/lib/Lex/PreprocessingRecord.cpp
+++ b/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);
}