[GRASS-SVN] r50563 - grass/trunk/lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jan 30 12:26:59 EST 2012


Author: glynn
Date: 2012-01-30 09:26:59 -0800 (Mon, 30 Jan 2012)
New Revision: 50563

Modified:
   grass/trunk/lib/gis/spawn.c
Log:
Close handles after spawning child process


Modified: grass/trunk/lib/gis/spawn.c
===================================================================
--- grass/trunk/lib/gis/spawn.c	2012-01-30 16:09:15 UTC (rev 50562)
+++ grass/trunk/lib/gis/spawn.c	2012-01-30 17:26:59 UTC (rev 50563)
@@ -343,6 +343,7 @@
     PROCESS_INFORMATION pi;
     BOOL result;
     DWORD exitcode;
+    int i;
 
     if (!shell) {
 	G_debug(3, "win_spawn: program = %s", program);
@@ -388,6 +389,10 @@
 
     CloseHandle(pi.hThread);
 
+    for (i = 0; i < 3; i++)
+	if (handles[i] != INVALID_HANDLE_VALUE)
+	    CloseHandle(handles[i]);
+
     if (!background) {
 	WaitForSingleObject(pi.hProcess, INFINITE);
 	if (!GetExitCodeProcess(pi.hProcess, &exitcode))
@@ -434,7 +439,10 @@
 	    handles[r->dst_fd] = get_handle(r->src_fd);
 	}
 	else {
-	    handles[r->dst_fd] = INVALID_HANDLE_VALUE;
+	    if (r->dst_fd < 3) {
+		CloseHandle(handles[r->dst_fd]);
+		handles[r->dst_fd] = INVALID_HANDLE_VALUE;
+	    }
 	    close(r->dst_fd);
 	}
     }



More information about the grass-commit mailing list