summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorcheatfate <ka@hardcore.kiev.ua>2017-12-12 16:53:09 +0200
committercheatfate <ka@hardcore.kiev.ua>2017-12-12 16:53:09 +0200
commite6722498595eabf6ef0ae314ad099c4108fde346 (patch)
treed92f6af7ac3566be2bae458ea4e292086ca87d50 /lib
parent59d45305629e54b8cc9a1f2e0991609363d792a4 (diff)
downloadNim-e6722498595eabf6ef0ae314ad099c4108fde346.tar.gz
Windows: Fix invalid handle value for `execProcesses`.
Windows. Fix named pipes leak.
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/osproc.nim18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim
index f762a713b..f61045663 100644
--- a/lib/pure/osproc.nim
+++ b/lib/pure/osproc.nim
@@ -273,7 +273,6 @@ proc execProcesses*(cmds: openArray[string],
               discard getExitCodeProcess(q[r].fProcessHandle, status)
               q[r].exitFlag = true
               q[r].exitStatus = status
-              discard closeHandle(q[r].fProcessHandle)
               break
       else:
         var status: cint = 1
@@ -313,11 +312,14 @@ proc execProcesses*(cmds: openArray[string],
                 w[r] = q[r].fProcessHandle
               inc(i)
             else:
-              q[r] = nil
               when defined(windows):
-                for c in r..MAXIMUM_WAIT_OBJECTS - 2:
-                  w[c] = w[c + 1]
-                dec(wcount)
+                for k in 0..wcount - 1:
+                  if w[k] == q[r].fProcessHandle:
+                    w[k] = w[wcount - 1]
+                    w[wcount - 1] = 0
+                    dec(wcount)
+                    break
+              q[r] = nil
             dec(ecount)
   else:
     for i in 0..high(cmds):
@@ -574,17 +576,17 @@ when defined(Windows) and not defined(useNimRtl):
             "Requested command not found: '$1'. OS error:" % command)
       else:
         raiseOSError(lastError, command)
-
     result.fProcessHandle = procInfo.hProcess
     result.fThreadHandle = procInfo.hThread
     result.id = procInfo.dwProcessId
     result.exitFlag = false
 
   proc close(p: Process) =
-    if poInteractive in p.options:
+    if poParentStreams notin p.options:
       discard closeHandle(p.inHandle)
       discard closeHandle(p.outHandle)
       discard closeHandle(p.errHandle)
+    discard closeHandle(p.fThreadHandle)
     discard closeHandle(p.fProcessHandle)
 
   proc suspend(p: Process) =
@@ -619,6 +621,7 @@ when defined(Windows) and not defined(useNimRtl):
     if status != STILL_ACTIVE:
       p.exitFlag = true
       p.exitStatus = status
+      discard closeHandle(p.fThreadHandle)
       discard closeHandle(p.fProcessHandle)
       result = status
     else:
@@ -635,6 +638,7 @@ when defined(Windows) and not defined(useNimRtl):
       discard getExitCodeProcess(p.fProcessHandle, status)
       p.exitFlag = true
       p.exitStatus = status
+      discard closeHandle(p.fThreadHandle)
       discard closeHandle(p.fProcessHandle)
       result = status