Fix memory leaks

This commit is contained in:
Hackerpilot 2016-05-11 16:41:42 -07:00
parent c602036e0f
commit 162a5fb332
2 changed files with 10 additions and 5 deletions

View File

@ -198,18 +198,21 @@ const(Module) parseModule(string fileName, ubyte[] code, RollbackAllocator* p,
MessageSet analyze(string fileName, const Module m, const StaticAnalysisConfig analysisConfig, MessageSet analyze(string fileName, const Module m, const StaticAnalysisConfig analysisConfig,
ref ModuleCache moduleCache, const(Token)[] tokens, bool staticAnalyze = true) ref ModuleCache moduleCache, const(Token)[] tokens, bool staticAnalyze = true)
{ {
import dsymbol.symbol : DSymbol;
if (!staticAnalyze) if (!staticAnalyze)
return null; return null;
auto symbolAllocator = new ASTAllocator; auto symbolAllocator = scoped!ASTAllocator();
auto first = scoped!FirstPass(m, internString(fileName), symbolAllocator, auto first = scoped!FirstPass(m, internString(fileName), symbolAllocator,
symbolAllocator, true, &moduleCache, null); symbolAllocator, true, &moduleCache, null);
first.run(); first.run();
secondPass(first.rootSymbol, first.moduleScope, moduleCache); secondPass(first.rootSymbol, first.moduleScope, moduleCache);
typeid(SemanticSymbol).destroy(first.rootSymbol); auto moduleScope = first.moduleScope;
const(Scope)* moduleScope = first.moduleScope; scope(exit) typeid(DSymbol).destroy(first.rootSymbol.acSymbol);
scope(exit) typeid(SemanticSymbol).destroy(first.rootSymbol);
scope(exit) typeid(Scope).destroy(first.moduleScope);
BaseAnalyzer[] checks; BaseAnalyzer[] checks;
if (analysisConfig.asm_style_check) if (analysisConfig.asm_style_check)

View File

@ -14,6 +14,7 @@ import std.path;
import std.stdio; import std.stdio;
import std.range; import std.range;
import std.experimental.lexer; import std.experimental.lexer;
import std.typecons : scoped;
import dparse.lexer; import dparse.lexer;
import dparse.parser; import dparse.parser;
import dparse.rollback_allocator; import dparse.rollback_allocator;
@ -138,7 +139,8 @@ else
const(string[]) absImportPaths = importPaths.map!(a => a.absolutePath() const(string[]) absImportPaths = importPaths.map!(a => a.absolutePath()
.buildNormalizedPath()).array(); .buildNormalizedPath()).array();
auto moduleCache = ModuleCache(new dsymbol.modulecache.ASTAllocator); auto alloc = scoped!(dsymbol.modulecache.ASTAllocator)();
auto moduleCache = ModuleCache(alloc);
if (absImportPaths.length) if (absImportPaths.length)
moduleCache.addImportPaths(absImportPaths); moduleCache.addImportPaths(absImportPaths);