bugfix: fixed memory leaks in osproc module
This commit is contained in:
parent
c9b67f724d
commit
a497b4d1cf
7 changed files with 185 additions and 127 deletions
|
|
@ -224,14 +224,6 @@ when not defined(useNimRtl):
|
|||
close(outp)
|
||||
close(p)
|
||||
|
||||
when false:
|
||||
proc deallocCStringArray(a: cstringArray) =
|
||||
var i = 0
|
||||
while a[i] != nil:
|
||||
dealloc(a[i])
|
||||
inc(i)
|
||||
dealloc(a)
|
||||
|
||||
when defined(Windows) and not defined(useNimRtl):
|
||||
# We need to implement a handle stream for Windows:
|
||||
type
|
||||
|
|
@ -491,6 +483,13 @@ elif not defined(useNimRtl):
|
|||
copyMem(result[i], addr(x[0]), x.len+1)
|
||||
inc(i)
|
||||
|
||||
proc deallocCStringArray(a: cstringArray) =
|
||||
var i = 0
|
||||
while a[i] != nil:
|
||||
dealloc(a[i])
|
||||
inc(i)
|
||||
dealloc(a)
|
||||
|
||||
proc startProcess(command: string,
|
||||
workingDir: string = "",
|
||||
args: openarray[string] = [],
|
||||
|
|
@ -537,18 +536,21 @@ elif not defined(useNimRtl):
|
|||
chck posix_spawn_file_actions_adddup2(fops, p_stderr[writeIdx], 2)
|
||||
|
||||
var e = if env == nil: EnvToCStringArray() else: ToCStringArray(env)
|
||||
|
||||
var a: cstringArray
|
||||
var res: cint
|
||||
if workingDir.len > 0: os.setCurrentDir(workingDir)
|
||||
if poUseShell notin options:
|
||||
var a = toCStringArray([extractFilename(command)], args)
|
||||
chck posix_spawn(pid, command, fops, attr, a, e)
|
||||
a = toCStringArray([extractFilename(command)], args)
|
||||
res = posix_spawn(pid, command, fops, attr, a, e)
|
||||
else:
|
||||
var x = addCmdArgs(command, args)
|
||||
var a = toCStringArray(["sh", "-c"], [x])
|
||||
chck posix_spawn(pid, "/bin/sh", fops, attr, a, e)
|
||||
|
||||
chck posix_spawn_file_actions_destroy(fops)
|
||||
chck posix_spawnattr_destroy(attr)
|
||||
a = toCStringArray(["sh", "-c"], [x])
|
||||
res = posix_spawn(pid, "/bin/sh", fops, attr, a, e)
|
||||
deallocCStringArray(a)
|
||||
deallocCStringArray(e)
|
||||
discard posix_spawn_file_actions_destroy(fops)
|
||||
discard posix_spawnattr_destroy(attr)
|
||||
chck res
|
||||
|
||||
else:
|
||||
|
||||
|
|
|
|||
|
|
@ -1774,10 +1774,10 @@ when not defined(EcmaScript) and not defined(NimrodVM):
|
|||
|
||||
# ----------------------------------------------------------------------------
|
||||
|
||||
proc atomicInc*(memLoc: var int, x: int = 1): int {.inline.}
|
||||
proc atomicInc*(memLoc: var int, x: int = 1): int {.inline, discardable.}
|
||||
## atomic increment of `memLoc`. Returns the value after the operation.
|
||||
|
||||
proc atomicDec*(memLoc: var int, x: int = 1): int {.inline.}
|
||||
proc atomicDec*(memLoc: var int, x: int = 1): int {.inline, discardable.}
|
||||
## atomic decrement of `memLoc`. Returns the value after the operation.
|
||||
|
||||
include "system/atomics"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue