reftable: handle block-writer initialization errors

2d5dbb37b2 (reftable/block: handle allocation failures, 2024-10-02)
taught `writer_reinit_block_writer()` to report initialization failures
and updated its callers, but `reftable_writer_new()` continued to ignore
the return value.

Consequently, the constructor could report success after block-writer
initialization had failed. Propagate the error and release the
constructor's allocations instead of returning an unusable writer.

Pointed out by GPT-5.6 Sol and Claude Opus 4.8.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Schindelin authored and Junio C Hamano committed 2026-08-12 09:05:49 -07:00
1 parent 633ac346ee
commit 47568fee94
1 file changed
+7 -1
+7 -1
View File
@@ -150,6 +150,7 @@ int reftable_writer_new(struct reftable_writer **out,
{
struct reftable_write_options opts = {0};
struct reftable_writer *wp;
int err;
if (_opts)
opts = *_opts;
@@ -177,7 +178,12 @@ int reftable_writer_new(struct reftable_writer **out,
wp->opts = opts;
wp->hash_id = hash_id;
wp->flush = flush_func;
writer_reinit_block_writer(wp, REFTABLE_BLOCK_TYPE_REF);
err = writer_reinit_block_writer(wp, REFTABLE_BLOCK_TYPE_REF);
if (err < 0) {
reftable_free(wp->block);
reftable_free(wp);
return err;
}
*out = wp;