Skip to content

Commit 162a5fb

Browse files
committed
Fix memory leaks
1 parent c602036 commit 162a5fb

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/analysis/run.d

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,18 +198,21 @@ const(Module) parseModule(string fileName, ubyte[] code, RollbackAllocator* p,
198198
MessageSet analyze(string fileName, const Module m, const StaticAnalysisConfig analysisConfig,
199199
ref ModuleCache moduleCache, const(Token)[] tokens, bool staticAnalyze = true)
200200
{
201+
import dsymbol.symbol : DSymbol;
202+
201203
if (!staticAnalyze)
202204
return null;
203205

204-
auto symbolAllocator = new ASTAllocator;
206+
auto symbolAllocator = scoped!ASTAllocator();
205207
auto first = scoped!FirstPass(m, internString(fileName), symbolAllocator,
206208
symbolAllocator, true, &moduleCache, null);
207209
first.run();
208210

209211
secondPass(first.rootSymbol, first.moduleScope, moduleCache);
210-
typeid(SemanticSymbol).destroy(first.rootSymbol);
211-
const(Scope)* moduleScope = first.moduleScope;
212-
212+
auto moduleScope = first.moduleScope;
213+
scope(exit) typeid(DSymbol).destroy(first.rootSymbol.acSymbol);
214+
scope(exit) typeid(SemanticSymbol).destroy(first.rootSymbol);
215+
scope(exit) typeid(Scope).destroy(first.moduleScope);
213216
BaseAnalyzer[] checks;
214217

215218
if (analysisConfig.asm_style_check)

src/main.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import std.path;
1414
import std.stdio;
1515
import std.range;
1616
import std.experimental.lexer;
17+
import std.typecons : scoped;
1718
import dparse.lexer;
1819
import dparse.parser;
1920
import dparse.rollback_allocator;
@@ -138,7 +139,8 @@ else
138139
const(string[]) absImportPaths = importPaths.map!(a => a.absolutePath()
139140
.buildNormalizedPath()).array();
140141

141-
auto moduleCache = ModuleCache(new dsymbol.modulecache.ASTAllocator);
142+
auto alloc = scoped!(dsymbol.modulecache.ASTAllocator)();
143+
auto moduleCache = ModuleCache(alloc);
142144

143145
if (absImportPaths.length)
144146
moduleCache.addImportPaths(absImportPaths);

0 commit comments

Comments
 (0)