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,
ref ModuleCache moduleCache, const(Token)[] tokens, bool staticAnalyze = true)
{
import dsymbol.symbol : DSymbol;
if (!staticAnalyze)
return null;
auto symbolAllocator = new ASTAllocator;
auto symbolAllocator = scoped!ASTAllocator();
auto first = scoped!FirstPass(m, internString(fileName), symbolAllocator,
symbolAllocator, true, &moduleCache, null);
first.run();
secondPass(first.rootSymbol, first.moduleScope, moduleCache);
typeid(SemanticSymbol).destroy(first.rootSymbol);
const(Scope)* moduleScope = first.moduleScope;
auto 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;
if (analysisConfig.asm_style_check)

View File

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