From 23430ccb042f11eda205c390d4c2a0d07d08b2e6 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 11 Aug 2014 21:29:24 +0000 Subject: unique_ptr-ify FileSystemStatCache::setNextStatCache And in the process, discover that FileManager::removeStatCache had a double-delete when removing an element from the middle of the list (at the beginning or the end of the list, there was no problem) and add a unit test to exercise the code path (which successfully crashed when run (with modifications to match the old API) without this patch applied) llvm-svn: 215388 --- clang/lib/Basic/FileManager.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'clang/lib/Basic/FileManager.cpp') diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 94bd3f8ccfd..e4a7f1e2575 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -64,20 +64,20 @@ FileManager::~FileManager() { delete VirtualDirectoryEntries[i]; } -void FileManager::addStatCache(FileSystemStatCache *statCache, +void FileManager::addStatCache(std::unique_ptr statCache, bool AtBeginning) { assert(statCache && "No stat cache provided?"); if (AtBeginning || !StatCache.get()) { - statCache->setNextStatCache(StatCache.release()); - StatCache.reset(statCache); + statCache->setNextStatCache(std::move(StatCache)); + StatCache = std::move(statCache); return; } FileSystemStatCache *LastCache = StatCache.get(); while (LastCache->getNextStatCache()) LastCache = LastCache->getNextStatCache(); - - LastCache->setNextStatCache(statCache); + + LastCache->setNextStatCache(std::move(statCache)); } void FileManager::removeStatCache(FileSystemStatCache *statCache) { @@ -96,7 +96,7 @@ void FileManager::removeStatCache(FileSystemStatCache *statCache) { PrevCache = PrevCache->getNextStatCache(); assert(PrevCache && "Stat cache not found for removal"); - PrevCache->setNextStatCache(statCache->getNextStatCache()); + PrevCache->setNextStatCache(statCache->takeNextStatCache()); } void FileManager::clearStatCaches() { -- cgit v1.2.3