Skip to content

Commit 7b91929

Browse files
peffgitster
authored andcommitted
run-command: fix segfault when cleaning forked async process
Callers of the run-command API may mark a child as "clean_on_exit"; it gets added to a list and killed when the main process dies. Since commit 46df690 (execv_dashed_external: wait for child on signal death, 2017-01-06), we respect an extra "wait_after_clean" flag, which we expect to find in the child_process struct. When Git is built with NO_PTHREADS, we start "struct async" processes by forking rather than spawning a thread. The resulting processes get added to the cleanup list but they don't have a child_process struct, and the cleanup function ends up dereferencing NULL. We should notice this case and assume that the processes do not need to be waited for (i.e., the same behavior they had before 46df690). Reported-by: Brandon Williams <[email protected]> Signed-off-by: Jeff King <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 46df690 commit 7b91929

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

run-command.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ static void cleanup_children(int sig, int in_signal)
4848

4949
kill(p->pid, sig);
5050

51-
if (p->process->wait_after_clean) {
51+
if (p->process && p->process->wait_after_clean) {
5252
p->next = children_to_wait_for;
5353
children_to_wait_for = p;
5454
} else {

0 commit comments

Comments
 (0)