aboutsummaryrefslogtreecommitdiff
path: root/run-command.c
diff options
context:
space:
mode:
authorDavid Gould <david@optimisefitness.com>2012-09-11 15:32:47 +0100
committerJunio C Hamano <gitster@pobox.com>2012-09-11 10:30:31 -0700
commitbdee397d7c2345d467548ef9446a2a63b72c5449 (patch)
tree71a4db98c94c786f0edb06839cc4c9b5cab40d98 /run-command.c
parentafe19ff7b55129d988e421ae1e0df4ec9659787a (diff)
downloadgit-bdee397d7c2345d467548ef9446a2a63b72c5449.tar.gz
git-bdee397d7c2345d467548ef9446a2a63b72c5449.tar.xz
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 <david@optimisefitness.com> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'run-command.c')
-rw-r--r--run-command.c13
1 files 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;
}
}