Skip to content

Commit

Permalink
fixup! mingw: kill child processes in a gentler way
Browse files Browse the repository at this point in the history
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 <johannes.schindelin@gmx.de>
  • Loading branch information
dscho committed May 23, 2017
1 parent 7cf4526 commit 3603d17
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions compat/win32/exit-process.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,18 @@ static int terminate_process_tree(HANDLE main_process, int exit_status)
break;
}

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

if (process) {
if (!TerminateProcess(process, exit_status << 8))
if (!TerminateProcess(process, exit_status))
ret = -1;
CloseHandle(process);
}
}
if (!TerminateProcess(main_process, exit_status))
ret = -1;
CloseHandle(main_process);

return ret;
}
Expand Down

0 comments on commit 3603d17

Please sign in to comment.