reftable: handle trivial allocation failures

Handle trivial allocation failures in the reftable library and its unit
tests.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2024-10-02 12:56:31 +02:00
committed by Junio C Hamano
parent 51afc709dc
commit 12b9078066
7 changed files with 67 additions and 14 deletions

View File

@ -598,6 +598,10 @@ int reftable_reader_new(struct reftable_reader **out,
int err;
REFTABLE_CALLOC_ARRAY(r, 1);
if (!r) {
err = REFTABLE_OUT_OF_MEMORY_ERROR;
goto done;
}
/*
* We need one extra byte to read the type of first block. We also
@ -627,7 +631,11 @@ int reftable_reader_new(struct reftable_reader **out,
r->size = file_size - footer_size(r->version);
r->source = *source;
r->name = xstrdup(name);
r->name = reftable_strdup(name);
if (!r->name) {
err = REFTABLE_OUT_OF_MEMORY_ERROR;
goto done;
}
r->hash_id = 0;
r->refcount = 1;