diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-06-05 22:05:31 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-06-05 22:05:31 +0000 |
commit | f878a84cc4d58035c0d622b988af6fb5f286f140 (patch) | |
tree | bd9a460c567f1a4a74e2895af0fcf86653e369e2 /clang/lib/Basic/SourceManager.cpp | |
parent | 024eff1edafedb33359a54ce42b4d7d17a06c30f (diff) | |
download | bcm5719-llvm-f878a84cc4d58035c0d622b988af6fb5f286f140.tar.gz bcm5719-llvm-f878a84cc4d58035c0d622b988af6fb5f286f140.zip |
Fix memory leak exposed by r304726.
When giving a ContentCache a null buffer, ignore the DoNotFree flag rather than
inheriting it onto whatever buffer we end up using for the file. Also ensure
that the main buffer is properly destroyed.
llvm-svn: 304740
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r-- | clang/lib/Basic/SourceManager.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp index c0cd2a8d2a1..fc4c6d30380 100644 --- a/clang/lib/Basic/SourceManager.cpp +++ b/clang/lib/Basic/SourceManager.cpp @@ -73,11 +73,11 @@ void ContentCache::replaceBuffer(llvm::MemoryBuffer *B, bool DoNotFree) { Buffer.setInt(DoNotFree? DoNotFreeFlag : 0); return; } - + if (shouldFreeBuffer()) delete Buffer.getPointer(); Buffer.setPointer(B); - Buffer.setInt(DoNotFree? DoNotFreeFlag : 0); + Buffer.setInt((B && DoNotFree) ? DoNotFreeFlag : 0); } llvm::MemoryBuffer *ContentCache::getBuffer(DiagnosticsEngine &Diag, @@ -362,9 +362,11 @@ void SourceManager::initializeForReplay(const SourceManager &Old) { // Set up our main file ID as a copy of the old source manager's main file. const SLocEntry &OldMainFile = Old.getSLocEntry(Old.getMainFileID()); assert(OldMainFile.isFile() && "main file is macro expansion?"); - setMainFileID(createFileID( - CloneContentCache(OldMainFile.getFile().getContentCache()), - SourceLocation(), OldMainFile.getFile().getFileCharacteristic(), 0, 0)); + auto *MainCC = CloneContentCache(OldMainFile.getFile().getContentCache()); + MemBufferInfos.push_back(MainCC); + setMainFileID(createFileID(MainCC, SourceLocation(), + OldMainFile.getFile().getFileCharacteristic(), + 0, 0)); // Ensure all SLocEntries are loaded from the external source. for (unsigned I = 0, N = Old.LoadedSLocEntryTable.size(); I != N; ++I) |