Re: [PATCH v2 04/21] strbuf: fix leak when `appendwholeline()` fails with EOF
- From
Jeff King <peff@peff.net>
- Date
- May 30, 2024, 07:16 UTC
- Message-ID
- <20240530071627.GE1949834@coredump.intra.peff.net>
- In-Reply-To
- <ZlcQjvAS-27S-mjw@tanuki>
On Wed, May 29, 2024 at 01:25:02PM +0200, Patrick Steinhardt wrote:
Show 8 quoted lines
> > If we really cared, though, I think you could check sb->alloc before the > > call to getdelim(), and then we'd know whether the original held an > > allocation or not (and we could restore its state). That's what other > > syscall-ish strbuf functions like strbuf_readlink() and strbuf_getcwd() > > do. > > Ah, I didn't know that we did similar things in other strbuf functions. > With that precedence I think it's less ugly to do this dance.
Yeah, I probably should have explained that better in my earlier email. ;)
Show 12 quoted lines
> > I saw only one questionable case. builtin/difftool.c does: > > > > if (strbuf_getline_nul(&lpath, fp)) > > break; > > > > without freeing lpath. But then...it does not free it in the case that > > we got a value, either! So I think it is leaking either way, and the > > solution, to strbuf_release(&lpath) outside of the loop, would fix both > > cases. > > Indeed. We also didn't free `rpath` and `info`. I do have a follow up to > this series already, so let me add those leak fixes to it.
Great! Thanks (as usual) for being receptive to me piling more things on your todo list. :)
-Peff