Re: [PATCH v3 3/7] odb: update `struct odb_write_stream` read() callback
- From
Jeff King <peff@peff.net>
- Date
- May 11, 2026, 17:58 UTC
- Message-ID
- <20260511175835.GA4811@coredump.intra.peff.net>
- In-Reply-To
- <20260402213220.2651523-4-jltobler@gmail.com>
On Thu, Apr 02, 2026 at 04:32:16PM -0500, Justin Tobler wrote:
Show 17 quoted lines
> @@ -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).
-Peff