Skip to content

Commit 3603d17

Browse files
committed
fixup! mingw: kill child processes in a gentler way
Seems that this maintainer managed to merge a revision without the last-minute changes. This fix makes sure that the exit_status is preserved, and that it is easier to reason about the main_process and why it is terminated and the handle is closed only once (I am looking at you, Coverity!). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 7cf4526 commit 3603d17

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

compat/win32/exit-process.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,18 @@ static int terminate_process_tree(HANDLE main_process, int exit_status)
6363
break;
6464
}
6565

66-
for (i = len - 1; i >= 0; i--) {
67-
HANDLE process = pids[i] == pid ? main_process :
68-
OpenProcess(PROCESS_TERMINATE, FALSE, pids[i]);
66+
for (i = len - 1; i > 0; i--) {
67+
HANDLE process = OpenProcess(PROCESS_TERMINATE, FALSE, pids[i]);
6968

7069
if (process) {
71-
if (!TerminateProcess(process, exit_status << 8))
70+
if (!TerminateProcess(process, exit_status))
7271
ret = -1;
7372
CloseHandle(process);
7473
}
7574
}
75+
if (!TerminateProcess(main_process, exit_status))
76+
ret = -1;
77+
CloseHandle(main_process);
7678

7779
return ret;
7880
}

0 commit comments

Comments
 (0)