From: Jeff King <peff@peff.net>
To: David Gould <david@optimisefitness.com>
Cc: git@vger.kernel.org
Subject: Re: Probable bug in file run-command.c function clear_child_for_cleanup
Date: Mon, 10 Sep 2012 09:44:06 -0400 [thread overview]
Message-ID: <20120910134406.GA7496@sigill.intra.peff.net> (raw)
In-Reply-To: <504CAB66.1050003@optimisefitness.com>
On Sun, Sep 09, 2012 at 03:44:54PM +0100, David Gould wrote:
> static void clear_child_for_cleanup(pid_t pid)
> {
> struct child_to_clean **last, *p;
>
> last = &children_to_clean;
> for (p = children_to_clean; p; p = p->next) {
> if (p->pid == pid) {
> *last = p->next;
> free(p);
> return;
> }
> }
> }
>
> It appears that last is intended to point to the next field that's
> being updated, but fails to "follow" the p pointer along the chain.
> The result is that children_to_clean will end up pointing to the
> entry after the deleted one, and all the entries before it will be
> lost. It'll only be fine in the case that the pid is that of the
> first entry in the chain.
Yes, it's a bug. We should update "last" on each iteration.
> You want something like:
>
> for (... {
> if (... {
> ...
> }
> last = &p->next;
> }
>
> or (probably clearer, but I haven't read your coding style guide, if
> there is one, and some people don't like this approach)
Yes, that's the correct fix. Care to submit a patch?
> for (p = children_to_clean; p; last = &p->next, p = p->next) {
> ...
That is OK, too, but I think I prefer the first one.
-Peff
next prev parent reply other threads:[~2012-09-10 13:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-09-09 14:44 Probable bug in file run-command.c function clear_child_for_cleanup David Gould
2012-09-10 13:44 ` Jeff King [this message]
2012-09-10 13:58 ` Erik Faye-Lund
2012-09-10 14:10 ` Jeff King
2012-09-10 20:00 ` Junio C Hamano
2012-09-10 20:01 ` Jeff King
2012-09-10 20:12 ` Junio C Hamano
2012-09-11 8:40 ` David Gould
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20120910134406.GA7496@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=david@optimisefitness.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).