Re: [PATCH v2 02/15] pack-bitmap: fix leak of haves/wants object lists
- From
Jeff King <peff@peff.net>
- Date
- Feb 15, 2020, 06:46 UTC
- Message-ID
- <20200215064654.GA1633703@coredump.intra.peff.net>
- In-Reply-To
- <20200215001552.GE11400@syl.local>
On Fri, Feb 14, 2020 at 04:15:52PM -0800, Taylor Blau wrote:
Show 14 quoted lines
> > +void object_list_free(struct object_list **list)
> > +{
> > + while (*list) {
> > + struct object_list *p = *list;
> > + *list = p->next;
> > + free(p);
> > + }
> > +}
>
> Hmm. I was going to write a comment saying more-or-less, "I think I'm
> nitpicking here, but I'm not crazy about this as a 'while' loop". But,
> when I wrote this as a 'for' loop instead, I wrote a use-after-free, and
> then when I rid the code of that, it wasn't any more readable than the
> version above.Yep, linked lists are deceptive that way.
This _could_ be converted to use the generic list.h macros. Or better still, we could probably ditch it entirely in favor of an object_array. But I'd prefer to do that separately, if at all.
-Peff