From: Junio C Hamano <gitster@pobox.com>
To: "Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Patrick Steinhardt <ps@pks.im>,
Johannes Schindelin <johannes.schindelin@gmx.de>
Subject: Re: [PATCH v2 03/11] reftable/block: check deflateInit() return value
Date: Wed, 05 Aug 2026 18:11:15 -0700 [thread overview]
Message-ID: <xmqqse4sm4ss.fsf@gitster.g> (raw)
In-Reply-To: <9bf7e737c740d8a80467ee3b38df9c86bbf7a566.1785954661.git.gitgitgadget@gmail.com> (Johannes Schindelin via GitGitGadget's message of "Wed, 05 Aug 2026 18:30:52 +0000")
"Johannes Schindelin via GitGitGadget" <gitgitgadget@gmail.com>
writes:
> The function already uses REFTABLE_ZLIB_ERROR for deflate()
> failures later in the code path (lines 171, 199), so returning
> the same error code for deflateInit() failure is consistent.
>
> Pointed out by Coverity.
>
> Assisted-by: Claude Opus 4.6
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
> reftable/block.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/reftable/block.c b/reftable/block.c
> index 920b3f4486..ec81fd0493 100644
> --- a/reftable/block.c
> +++ b/reftable/block.c
> @@ -87,7 +87,8 @@ int block_writer_init(struct block_writer *bw, uint8_t typ, uint8_t *block,
> REFTABLE_CALLOC_ARRAY(bw->zstream, 1);
> if (!bw->zstream)
> return REFTABLE_OUT_OF_MEMORY_ERROR;
> - deflateInit(bw->zstream, 9);
> + if (deflateInit(bw->zstream, 9) != Z_OK)
> + return REFTABLE_ZLIB_ERROR;
> }
Presumably bw->zstream occupies some memory allocated on the heap.
Does a failing deflateInit() release it? If not, do we leak memory
here? Or do we need
if (deflateInit(bw->zstream, 9) !+ Z_OK) {
REFTABLE_FREE_AND_NULL(bw->zstream);
return REFTABLE_ZLIB_ERROR;
}
here?
Noticing and returning an error is a good first step. The only
caller of it is reftable/writer.c:writer_reinit_block_writer(), and
it checks and relays the error code from here to its callers, but
not all callers of it check the error condition. The most blatant
offender being reftable_writer_new() that happily keeps going. I do
not know if we end up calling zlib on bw->zstream for such a broken
block_writer(), as I didn't trace the call graph fully myself.
Stepping back a bit, if REFTABLE_CALLOC_ARRAY() fails, bw->zstream
would be NULL, and a caller that does not check the return value of
writer_reinit_block_writer() would be holding a block writer whose
zstream is NULL. If the block writer is eventually passed to the
block_writer_release() function, we would call deflateEnd() on it.
next prev parent reply other threads:[~2026-08-06 1:11 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 22:48 [PATCH 00/11] coverity: fix unchecked returns Johannes Schindelin via GitGitGadget
2026-07-14 22:48 ` [PATCH 01/11] http: die on curl_easy_duphandle failure in get_active_slot Johannes Schindelin via GitGitGadget
2026-07-14 22:48 ` [PATCH 02/11] config: propagate launch_editor() failure in show_editor() Johannes Schindelin via GitGitGadget
2026-07-15 6:58 ` Patrick Steinhardt
2026-07-14 22:48 ` [PATCH 03/11] reftable/block: check deflateInit() return value Johannes Schindelin via GitGitGadget
2026-07-14 22:48 ` [PATCH 04/11] reftable tests: check reftable_table_init_ref_iterator() return Johannes Schindelin via GitGitGadget
2026-07-14 22:48 ` [PATCH 05/11] last-modified: handle repo_parse_commit() failures Johannes Schindelin via GitGitGadget
2026-07-15 1:15 ` Junio C Hamano
2026-07-20 5:09 ` Junio C Hamano
2026-08-05 14:27 ` Johannes Schindelin
2026-07-14 22:48 ` [PATCH 06/11] compat/pread: check initial lseek for errors Johannes Schindelin via GitGitGadget
2026-07-15 6:58 ` Patrick Steinhardt
2026-08-05 14:29 ` Johannes Schindelin
2026-07-14 22:48 ` [PATCH 07/11] transport-helper: check dup() return in get_exporter Johannes Schindelin via GitGitGadget
2026-07-15 6:58 ` Patrick Steinhardt
2026-07-14 22:48 ` [PATCH 08/11] transport-helper: warn when export-marks file cannot be finalized Johannes Schindelin via GitGitGadget
2026-07-14 22:48 ` [PATCH 09/11] bisect: check strbuf_getline_lf return when reading terms Johannes Schindelin via GitGitGadget
2026-07-15 1:17 ` Junio C Hamano
2026-07-20 5:09 ` Junio C Hamano
2026-08-05 14:33 ` Johannes Schindelin
2026-07-14 22:48 ` [PATCH 10/11] bisect: check get_terms return at all call sites Johannes Schindelin via GitGitGadget
2026-07-15 6:58 ` Patrick Steinhardt
2026-08-05 14:57 ` Johannes Schindelin
2026-07-14 22:48 ` [PATCH 11/11] bisect: handle dup() failure when redirecting stdout Johannes Schindelin via GitGitGadget
2026-07-15 6:58 ` Patrick Steinhardt
2026-08-05 16:44 ` Johannes Schindelin
2026-08-05 18:30 ` [PATCH v2 00/11] coverity: fix unchecked returns Johannes Schindelin via GitGitGadget
2026-08-05 18:30 ` [PATCH v2 01/11] http: die on curl_easy_duphandle failure in get_active_slot Johannes Schindelin via GitGitGadget
2026-08-05 18:30 ` [PATCH v2 02/11] config: propagate launch_editor() failure in show_editor() Johannes Schindelin via GitGitGadget
2026-08-05 18:30 ` [PATCH v2 03/11] reftable/block: check deflateInit() return value Johannes Schindelin via GitGitGadget
2026-08-06 1:11 ` Junio C Hamano [this message]
2026-08-05 18:30 ` [PATCH v2 04/11] reftable tests: check reftable_table_init_ref_iterator() return Johannes Schindelin via GitGitGadget
2026-08-05 18:30 ` [PATCH v2 05/11] last-modified: handle repo_parse_commit() failures Johannes Schindelin via GitGitGadget
2026-08-05 18:30 ` [PATCH v2 06/11] compat/pread: check initial lseek for errors Johannes Schindelin via GitGitGadget
2026-08-05 18:30 ` [PATCH v2 07/11] transport-helper: check dup() return in get_exporter Johannes Schindelin via GitGitGadget
2026-08-05 18:30 ` [PATCH v2 08/11] transport-helper: warn when export-marks file cannot be finalized Johannes Schindelin via GitGitGadget
2026-08-05 18:30 ` [PATCH v2 09/11] bisect: check strbuf_getline_lf return when reading terms Johannes Schindelin via GitGitGadget
2026-08-05 18:30 ` [PATCH v2 10/11] bisect: check get_terms return at all call sites Johannes Schindelin via GitGitGadget
2026-08-05 20:26 ` Junio C Hamano
2026-08-05 18:31 ` [PATCH v2 11/11] bisect: handle dup() failure when redirecting stdout Johannes Schindelin via GitGitGadget
2026-08-06 15:41 ` Jeff King
2026-08-06 17:31 ` Junio C Hamano
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=xmqqse4sm4ss.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=johannes.schindelin@gmx.de \
--cc=ps@pks.im \
/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