Stop leaking memory from Module and FileUnit.

Also, disallow creating Modules and FileUnits on the stack. They must always
live as long as the ASTContext.

<rdar://problem/15596964>

Swift SVN r13671
This commit is contained in:
Jordan Rose
2014-02-08 02:12:57 +00:00
parent 1e3fd1a5b1
commit cbcf17f9bd
11 changed files with 37 additions and 14 deletions

View File

@@ -84,6 +84,7 @@ void BuiltinUnit::LookupCache::lookupValue(Identifier Name, NLKind LookupKind,
// Out-of-line because std::unique_ptr wants LookupCache to be complete.
BuiltinUnit::BuiltinUnit(Module &M)
: FileUnit(FileUnitKind::Builtin, M) {
M.Ctx.addDestructorCleanup(*this);
}
//===----------------------------------------------------------------------===//
@@ -269,6 +270,12 @@ void SourceLookupCache::lookupClassMember(AccessPathTy accessPath,
// Module Implementation
//===----------------------------------------------------------------------===//
Module::Module(Identifier name, ASTContext &ctx)
: DeclContext(DeclContextKind::Module, nullptr), Ctx(ctx), Name(name) {
ctx.addDestructorCleanup(*this);
}
void Module::addFile(FileUnit &newFile) {
// Require Main and REPL files to be the first file added.
assert(Files.empty() ||
@@ -1099,6 +1106,7 @@ SourceFile::SourceFile(Module &M, SourceFileKind K,
Optional<unsigned> bufferID, bool hasBuiltinModuleAccess)
: FileUnit(FileUnitKind::Source, M),
BufferID(bufferID ? *bufferID : -1), Kind(K) {
M.Ctx.addDestructorCleanup(*this);
performAutoImport(*this, hasBuiltinModuleAccess);
}