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
Jeff King <peff@peff.net>
Date
Sep 11, 2012, 15:20 UTC
Message-ID
<20120911152041.GA11994@sigill.intra.peff.net>
In-Reply-To
<1347373967-29248-1-git-send-email-david@optimisefitness.com>
On Tue, Sep 11, 2012 at 03:32:47PM +0100, David Gould wrote:
> Subject: Re: [PATCH] clear_child_for_cleanup must correctly manage
>   children_to_clean

Thanks for the patch. Overall it looks good, but let me nit-pick your commit message a little (not because it is that horrible, but because you are so close to perfect that I want to fix the minor things and then encourage you to submit more patches :) ).

Your subject is a bit vague, and it is not clear if it is not correct now, and this is a bugfix, or if it is a feature enhancement. I would have said something like:

  Subject: fix broken list iteration in clear_child_for_cleanup

which is _also_ vague about what exactly the breakage is, but is clear that this is a bugfix. So then you can go on to describe the actual problem:

  We iterate through the list of children to cleanup, but do not keep
  our "last" pointer up to date. As a result, we may end up cutting off
  part of the list instead of removing a single element.
And then describe your fix:
> 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.
which I think is good.
Show 12 quoted lines
> -	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;
>  		}

I think using the indirect pointer is a nice compromise; it makes it clear from just the for loop that this is not an ordinary for-each traversal. You could hoist the extra pointer out of the conditional and save one set of parentheses in the "if" statement, but I don't think it is a big deal either way.

Acked-by: Jeff King <peff@peff.net>
Thanks for the bug report and the patch.
-Peff
Previous: David GouldNext: Junio C Hamano
Message 2 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.