mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Fix leak of LookupCache
The lookup cache isn't allocated in the ASTContext, so seting up a destructor cleanup isn't sufficient to get the memory released. Luckily SourceFile and BuiltinUnit already have their own destructor called, so we can use std::unique_ptr. rdar://problem/22387897 Swift SVN r31561
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#include "llvm/ADT/TinyPtrVector.h"
|
||||
#include "llvm/ADT/SmallPtrSet.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/Support/MD5.h"
|
||||
#include "llvm/Support/MemoryBuffer.h"
|
||||
#include "llvm/Support/Path.h"
|
||||
@@ -60,10 +61,8 @@ public:
|
||||
BuiltinUnit::LookupCache &BuiltinUnit::getCache() const {
|
||||
// FIXME: This leaks. Sticking this into ASTContext isn't enough because then
|
||||
// the DenseMap will leak.
|
||||
if (!Cache) {
|
||||
const_cast<BuiltinUnit *>(this)->Cache = new LookupCache();
|
||||
getASTContext().addDestructorCleanup(*Cache);
|
||||
}
|
||||
if (!Cache)
|
||||
const_cast<BuiltinUnit *>(this)->Cache = llvm::make_unique<LookupCache>();
|
||||
return *Cache;
|
||||
}
|
||||
|
||||
@@ -165,8 +164,8 @@ using SourceLookupCache = SourceFile::LookupCache;
|
||||
|
||||
SourceLookupCache &SourceFile::getCache() const {
|
||||
if (!Cache) {
|
||||
const_cast<SourceFile *>(this)->Cache = new SourceLookupCache(*this);
|
||||
getASTContext().addDestructorCleanup(*Cache);
|
||||
const_cast<SourceFile *>(this)->Cache =
|
||||
llvm::make_unique<SourceLookupCache>(*this);
|
||||
}
|
||||
return *Cache;
|
||||
}
|
||||
@@ -1442,7 +1441,7 @@ void SourceFile::clearLookupCache() {
|
||||
|
||||
// Abandon any current cache. We'll rebuild it on demand.
|
||||
Cache->invalidate();
|
||||
Cache = nullptr;
|
||||
Cache.reset();
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user