run-command.c: fix broken list iteration in clear_child_for_cleanup
authorDavid Gould <david@optimisefitness.com>
Tue, 11 Sep 2012 14:32:47 +0000 (15:32 +0100)
committerJunio C Hamano <gitster@pobox.com>
Tue, 11 Sep 2012 17:30:31 +0000 (10:30 -0700)
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 <david@optimisefitness.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
run-command.c

index 0204aaf7e8d6465900060a17552e26c74d2df520..d1d58d3e21bdcc8f80bda7aadb35ccd5066f4b38 100644 (file)
@@ -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;
                }
        }