[GRASS-SVN] r50573 - grass/branches/develbranch_6/lib/gis

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jan 30 16:06:37 EST 2012


Author: hamish
Date: 2012-01-30 13:06:37 -0800 (Mon, 30 Jan 2012)
New Revision: 50573

Modified:
   grass/branches/develbranch_6/lib/gis/spawn.c
Log:
Glynn: Close handles after spawning child process (merge r50563 from trunk, see #1276)

Modified: grass/branches/develbranch_6/lib/gis/spawn.c
===================================================================
--- grass/branches/develbranch_6/lib/gis/spawn.c	2012-01-30 20:36:16 UTC (rev 50572)
+++ grass/branches/develbranch_6/lib/gis/spawn.c	2012-01-30 21:06:37 UTC (rev 50573)
@@ -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