From a4288c4aa05075cd45fd4de61d95ffe920fe6441 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Sat, 10 Dec 2011 01:38:26 +0000 Subject: [PATCH] In ContentCache::replaceBuffer, add sanity check to make sure that we do not free a buffer and then continue using it. rdar://10359140. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146308 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Basic/SourceManager.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index 85fe474d66..18026dbdb7 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -71,7 +71,11 @@ unsigned ContentCache::getSize() const { void ContentCache::replaceBuffer(const llvm::MemoryBuffer *B, bool DoNotFree) { - assert(B != Buffer.getPointer()); + if (B == Buffer.getPointer()) { + assert(0 && "Replacing with the same buffer"); + Buffer.setInt(DoNotFree? DoNotFreeFlag : 0); + return; + } if (shouldFreeBuffer()) delete Buffer.getPointer(); -- 2.50.1