From bdee397d7c2345d467548ef9446a2a63b72c5449 Mon Sep 17 00:00:00 2001 From: David Gould Date: Tue, 11 Sep 2012 15:32:47 +0100 Subject: [PATCH] run-command.c: fix broken list iteration in clear_child_for_cleanup Iterate through children_to_clean using 'next' fields but with an extra level of indirection. This allows us to update the chain when we remove a child and saves us managing several variables around the loop mechanism. Signed-off-by: David Gould Acked-by: Jeff King Signed-off-by: Junio C Hamano --- run-command.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/run-command.c b/run-command.c index 0204aaf7e..d1d58d3e2 100644 --- a/run-command.c +++ b/run-command.c @@ -49,13 +49,14 @@ static void mark_child_for_cleanup(pid_t pid) static void clear_child_for_cleanup(pid_t pid) { - struct child_to_clean **last, *p; + struct child_to_clean **pp; - last = &children_to_clean; - for (p = children_to_clean; p; p = p->next) { - if (p->pid == pid) { - *last = p->next; - free(p); + for (pp = &children_to_clean; *pp; pp = &(*pp)->next) { + struct child_to_clean *clean_me = *pp; + + if (clean_me->pid == pid) { + *pp = clean_me->next; + free(clean_me); return; } } -- 2.26.2