#BUGFIX by stefan
authorStefan Vogel <sv@exept.de>
Tue, 22 Jan 2019 17:17:23 +0100
changeset 23635 b01b7b318310
parent 23634 6d3efff0d654
child 23636 b9e5840e2c22
#BUGFIX by stefan class: OSProcess added: #releasePid changed: #numericPid #startProcess Close process handle when process finishes. No longer leaks process handles in Windows.
OSProcess.st
--- a/OSProcess.st	Tue Jan 22 17:03:14 2019 +0100
+++ b/OSProcess.st	Tue Jan 22 17:17:23 2019 +0100
@@ -525,11 +525,10 @@
      or nil if the command has not yet been started.
      Always return an integer, even in windows where pid is a handle-"
 
-    (pid isNil or:[pid isInteger]) ifTrue:[
-        ^ pid.
+    pid isOsHandle ifTrue:[
+        ^ pid pid.
     ].
-
-    ^ pid pid.
+    ^ pid.  "Integer or nil"
 
     "Created: / 19-07-2018 / 16:21:25 / Stefan Vogel"
     "Modified (comment): / 20-11-2018 / 16:50:26 / Stefan Vogel"
@@ -628,6 +627,20 @@
 
 !OSProcess methodsFor:'private'!
 
+releasePid
+    "only used in Windows, where pid is a handle that must be released"
+
+    |pidHandle|
+
+    pidHandle := pid.
+    pidHandle isOsHandle ifFalse:[
+        ^ self.
+    ].
+
+    pid := pidHandle pid.   "remember the numeric value"
+    pidHandle close.
+!
+
 setupShufflerForInput:aStream
     "if aStream is an internal Stream, set up a pipe for the command input.
      Start a process that shuffles the data from the internal stream into the pipe
@@ -909,12 +922,6 @@
                 exitStatus := status.
                 self terminate.
 
-                "/ shufflerProcesses do:[:eachProcess|
-                "/     "terminate the shuffler processes.
-                "/      They close the local side of the pipe when being terminated"
-                "/    eachProcess terminate.
-                "/ ].
-                
                 finishSema signal.
                 terminateActionBlock notNil ifTrue:[
                     callingProcess isDead ifTrue:[
@@ -929,6 +936,9 @@
                             ]        
                     ].    
                 ].
+
+                self releasePid.
+
                 UserPreferences current logExecutedOSCommands ifTrue:[
                     Transcript 
                         showCR:(('OS command finished: %1 status: %2'