[PATCH v3 03/12] reftable: handle block-writer initialization errors
"Johannes Schindelin via GitGitGadget" <[email protected]>
| Newsgroups | org.kernel.vger.git |
|---|---|
| Message-ID | <c689148aef4302df2a370b78f30c185cd21a42c9.1786521801.git.gitgitgadget@gmail.com> |
From: Johannes Schindelin <[email protected]> 2d5dbb37b284 (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 <[email protected]> --- reftable/writer.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/reftable/writer.c b/reftable/writer.c index d969a6a021..073b9bbd89 100644 --- a/reftable/writer.c +++ b/reftable/writer.c @@ -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; -- gitgitgadget