summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rwxr-xr-xlib/pure/osproc.nim34
-rwxr-xr-xlib/system.nim4
2 files changed, 20 insertions, 18 deletions
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim
index b1b22f0b8..03c3def4d 100755
--- a/lib/pure/osproc.nim
+++ b/lib/pure/osproc.nim
@@ -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:
     
diff --git a/lib/system.nim b/lib/system.nim
index 153479bb4..545c8f821 100755
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -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"