diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-08-11 21:29:24 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-08-11 21:29:24 +0000 |
commit | 23430ccb042f11eda205c390d4c2a0d07d08b2e6 (patch) | |
tree | 8753c0e6cd148fe8b0bd60064a55ff3d6da6893f /clang/lib/Basic/FileManager.cpp | |
parent | be4b5171d3663eaee01823c33148de081ffe9e80 (diff) | |
download | llvm-23430ccb042f11eda205c390d4c2a0d07d08b2e6.zip llvm-23430ccb042f11eda205c390d4c2a0d07d08b2e6.tar.gz llvm-23430ccb042f11eda205c390d4c2a0d07d08b2e6.tar.bz2 |
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
Diffstat (limited to 'clang/lib/Basic/FileManager.cpp')
-rw-r--r-- | clang/lib/Basic/FileManager.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 94bd3f8..e4a7f1e 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<FileSystemStatCache> 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() { |