fix open file leak when running --debugger:native (#13832)
This commit is contained in:
parent
c2d29eb3e0
commit
d3020af44d
2 changed files with 16 additions and 6 deletions
|
|
@ -1924,8 +1924,8 @@ proc shouldRecompile(m: BModule; code: Rope, cfile: Cfile): bool =
|
||||||
# it would generate multiple 'main' procs, for instance.
|
# it would generate multiple 'main' procs, for instance.
|
||||||
|
|
||||||
proc writeModule(m: BModule, pending: bool) =
|
proc writeModule(m: BModule, pending: bool) =
|
||||||
|
template onExit() = close(m.ndi, m.config)
|
||||||
let cfile = getCFile(m)
|
let cfile = getCFile(m)
|
||||||
|
|
||||||
if true or optForceFullMake in m.config.globalOptions:
|
if true or optForceFullMake in m.config.globalOptions:
|
||||||
if moduleHasChanged(m.g.graph, m.module):
|
if moduleHasChanged(m.g.graph, m.module):
|
||||||
genInitCode(m)
|
genInitCode(m)
|
||||||
|
|
@ -1943,6 +1943,7 @@ proc writeModule(m: BModule, pending: bool) =
|
||||||
when hasTinyCBackend:
|
when hasTinyCBackend:
|
||||||
if conf.cmd == cmdRun:
|
if conf.cmd == cmdRun:
|
||||||
tccgen.compileCCode($code)
|
tccgen.compileCCode($code)
|
||||||
|
onExit()
|
||||||
return
|
return
|
||||||
|
|
||||||
if not shouldRecompile(m, code, cf): cf.flags = {CfileFlag.Cached}
|
if not shouldRecompile(m, code, cf): cf.flags = {CfileFlag.Cached}
|
||||||
|
|
@ -1966,7 +1967,7 @@ proc writeModule(m: BModule, pending: bool) =
|
||||||
obj: completeCfilePath(m.config, toObjFile(m.config, cfile)), flags: {})
|
obj: completeCfilePath(m.config, toObjFile(m.config, cfile)), flags: {})
|
||||||
if not fileExists(cf.obj): cf.flags = {CfileFlag.Cached}
|
if not fileExists(cf.obj): cf.flags = {CfileFlag.Cached}
|
||||||
addFileToCompile(m.config, cf)
|
addFileToCompile(m.config, cf)
|
||||||
close(m.ndi)
|
onExit()
|
||||||
|
|
||||||
proc updateCachedModule(m: BModule) =
|
proc updateCachedModule(m: BModule) =
|
||||||
let cfile = getCFile(m)
|
let cfile = getCFile(m)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ type
|
||||||
enabled: bool
|
enabled: bool
|
||||||
f: File
|
f: File
|
||||||
buf: string
|
buf: string
|
||||||
|
filename: AbsoluteFile
|
||||||
|
syms: seq[PSym]
|
||||||
|
|
||||||
proc doWrite(f: var NdiFile; s: PSym; conf: ConfigRef) =
|
proc doWrite(f: var NdiFile; s: PSym; conf: ConfigRef) =
|
||||||
f.buf.setLen 0
|
f.buf.setLen 0
|
||||||
|
|
@ -28,13 +30,20 @@ proc doWrite(f: var NdiFile; s: PSym; conf: ConfigRef) =
|
||||||
f.f.writeLine("\t", toFullPath(conf, s.info), "\t", f.buf)
|
f.f.writeLine("\t", toFullPath(conf, s.info), "\t", f.buf)
|
||||||
|
|
||||||
template writeMangledName*(f: NdiFile; s: PSym; conf: ConfigRef) =
|
template writeMangledName*(f: NdiFile; s: PSym; conf: ConfigRef) =
|
||||||
if f.enabled: doWrite(f, s, conf)
|
if f.enabled: f.syms.add s
|
||||||
|
|
||||||
proc open*(f: var NdiFile; filename: AbsoluteFile; conf: ConfigRef) =
|
proc open*(f: var NdiFile; filename: AbsoluteFile; conf: ConfigRef) =
|
||||||
f.enabled = not filename.isEmpty
|
f.enabled = not filename.isEmpty
|
||||||
if f.enabled:
|
if f.enabled:
|
||||||
f.f = open(filename.string, fmWrite, 8000)
|
f.filename = filename
|
||||||
f.buf = newStringOfCap(20)
|
f.buf = newStringOfCap(20)
|
||||||
|
|
||||||
proc close*(f: var NdiFile) =
|
proc close*(f: var NdiFile, conf: ConfigRef) =
|
||||||
if f.enabled: close(f.f)
|
if f.enabled:
|
||||||
|
f.f = open(f.filename.string, fmWrite, 8000)
|
||||||
|
doAssert f.f != nil, f.filename.string
|
||||||
|
for s in f.syms:
|
||||||
|
doWrite(f, s, conf)
|
||||||
|
close(f.f)
|
||||||
|
f.syms.reset
|
||||||
|
f.filename.reset
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue