git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] clear_child_for_cleanup must correctly manage children_to_clean

From
Erik Faye-Lund <kusmabite@gmail.com>
Date
Sep 11, 2012, 15:30 UTC
Message-ID
<CABPQNSYEiw2hw-S5x5YYJWrWYR6hNWBqudvHR=fxoHf0380jsA@mail.gmail.com>
In-Reply-To
<1347373967-29248-1-git-send-email-david@optimisefitness.com>
On Tue, Sep 11, 2012 at 4:32 PM, David Gould <david@optimisefitness.com> wrote:
Show 35 quoted lines
> 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.
> ---
>  run-command.c |   12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/run-command.c b/run-command.c
> index f9922b9..c42d63b 100644
> --- a/run-command.c
> +++ b/run-command.c
> @@ -53,13 +53,13 @@ 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) {
> +               if ((*pp)->pid == pid) {
> +                       struct child_to_clean *clean_me = *pp;
> +                       *pp = clean_me->next;
> +                       free(clean_me);
>                         return;
>                 }
>         }
> --
> 1.7.9.5
>
Looks good to me. Thanks :)
Previous: Junio C HamanoNext: David Gould
Message 4 of 6 in “clear_child_for_cleanup must correctly manage children_to_clean”
  1. clear_child_for_cleanup must correctly manage children_to_cleanDavid Gould, Sep 11, 2012
  2. Jeff KingSep 11, 2012
  3. Junio C HamanoSep 11, 2012
  4. Erik Faye-LundSep 11, 2012
  5. [PATCHv2] fix broken list iteration in clear_child_for_cleanupDavid Gould, Sep 11, 2012
  6. Junio C HamanoSep 11, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.