Subject: Re: [PATCH v3 3/7] odb: update `struct odb_write_stream` read() callback

From: Justin Tobler <[email-masked]>
Date: Tue, 12 May 2026 10:19:13 -0500

On 26/05/11 01:58PM, Jeff King wrote:
> On Thu, Apr 02, 2026 at 04:32:16PM -0500, Justin Tobler wrote:
> 
> > @@ -1098,9 +1099,16 @@ int odb_source_loose_write_stream(struct odb_source *source,
> >  		unsigned char *in0 = stream.next_in;
> >  
> >  		if (!stream.avail_in && !in_stream->is_finished) {
> > -			const void *in = in_stream->read(in_stream, &stream.avail_in);
> > -			stream.next_in = (void *)in;
> > -			in0 = (unsigned char *)in;
> > +			ssize_t read_len = odb_write_stream_read(in_stream, buf,
> > +								 sizeof(buf));
> > +			if (read_len < 0) {
> > +				err = -1;
> > +				goto cleanup;
> > +			}
> > +
> > +			stream.avail_in = read_len;
> > +			stream.next_in = buf;
> > +			in0 = buf;
> 
> If we hit this "goto cleanup", we'll leak the "fd" descriptor opened
> earlier. We either need to close(fd) here, or do so in the cleanup
> handler (but that means consistently setting fd to a sentinel value
> after we close it, which we do not currently do).
> 
> Noticed by Coverity (I guess this series just hit "jch", since it's
> "new" as of today's run).

Thanks, I will send another version to fix this leak.

-Justin