Skip to content

Commit bdee397

Browse files
David Gouldgitster
authored andcommitted
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 <[email protected]> Acked-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent afe19ff commit bdee397

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

run-command.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,14 @@ static void mark_child_for_cleanup(pid_t pid)
4949

5050
static void clear_child_for_cleanup(pid_t pid)
5151
{
52-
struct child_to_clean **last, *p;
52+
struct child_to_clean **pp;
5353

54-
last = &children_to_clean;
55-
for (p = children_to_clean; p; p = p->next) {
56-
if (p->pid == pid) {
57-
*last = p->next;
58-
free(p);
54+
for (pp = &children_to_clean; *pp; pp = &(*pp)->next) {
55+
struct child_to_clean *clean_me = *pp;
56+
57+
if (clean_me->pid == pid) {
58+
*pp = clean_me->next;
59+
free(clean_me);
5960
return;
6061
}
6162
}

0 commit comments

Comments
 (0)