Przeglądaj źródła

Close handles after spawning child process

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@50563 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements 13 lat temu
rodzic
commit
a049ea0396
1 zmienionych plików z 9 dodań i 1 usunięć
  1. 9 1
      lib/gis/spawn.c

+ 9 - 1
lib/gis/spawn.c

@@ -343,6 +343,7 @@ static int win_spawn(const char *cmd, const char **argv, const char **envp,
     PROCESS_INFORMATION pi;
     PROCESS_INFORMATION pi;
     BOOL result;
     BOOL result;
     DWORD exitcode;
     DWORD exitcode;
+    int i;
 
 
     if (!shell) {
     if (!shell) {
 	G_debug(3, "win_spawn: program = %s", program);
 	G_debug(3, "win_spawn: program = %s", program);
@@ -388,6 +389,10 @@ static int win_spawn(const char *cmd, const char **argv, const char **envp,
 
 
     CloseHandle(pi.hThread);
     CloseHandle(pi.hThread);
 
 
+    for (i = 0; i < 3; i++)
+	if (handles[i] != INVALID_HANDLE_VALUE)
+	    CloseHandle(handles[i]);
+
     if (!background) {
     if (!background) {
 	WaitForSingleObject(pi.hProcess, INFINITE);
 	WaitForSingleObject(pi.hProcess, INFINITE);
 	if (!GetExitCodeProcess(pi.hProcess, &exitcode))
 	if (!GetExitCodeProcess(pi.hProcess, &exitcode))
@@ -434,7 +439,10 @@ static void do_redirects(struct redirect *redirects, int num_redirects, HANDLE h
 	    handles[r->dst_fd] = get_handle(r->src_fd);
 	    handles[r->dst_fd] = get_handle(r->src_fd);
 	}
 	}
 	else {
 	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);
 	    close(r->dst_fd);
 	}
 	}
     }
     }