reftable/iter: handle allocation failures when creating indexed table iter
Handle allocation failures in `new_indexed_table_ref_iter()`. While at it, rename the function to match our coding style. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
5b67cc6477
commit
cc6a9af5d7
@ -181,14 +181,20 @@ static int indexed_table_ref_iter_next(void *p, struct reftable_record *rec)
|
||||
}
|
||||
}
|
||||
|
||||
int new_indexed_table_ref_iter(struct indexed_table_ref_iter **dest,
|
||||
int indexed_table_ref_iter_new(struct indexed_table_ref_iter **dest,
|
||||
struct reftable_reader *r, uint8_t *oid,
|
||||
int oid_len, uint64_t *offsets, int offset_len)
|
||||
{
|
||||
struct indexed_table_ref_iter empty = INDEXED_TABLE_REF_ITER_INIT;
|
||||
struct indexed_table_ref_iter *itr = reftable_calloc(1, sizeof(*itr));
|
||||
struct indexed_table_ref_iter *itr;
|
||||
int err = 0;
|
||||
|
||||
itr = reftable_calloc(1, sizeof(*itr));
|
||||
if (!itr) {
|
||||
err = REFTABLE_OUT_OF_MEMORY_ERROR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
*itr = empty;
|
||||
itr->r = r;
|
||||
strbuf_add(&itr->oid, oid, oid_len);
|
||||
@ -197,10 +203,16 @@ int new_indexed_table_ref_iter(struct indexed_table_ref_iter **dest,
|
||||
itr->offset_len = offset_len;
|
||||
|
||||
err = indexed_table_ref_iter_next_block(itr);
|
||||
if (err < 0)
|
||||
goto out;
|
||||
|
||||
*dest = itr;
|
||||
err = 0;
|
||||
|
||||
out:
|
||||
if (err < 0) {
|
||||
*dest = NULL;
|
||||
reftable_free(itr);
|
||||
} else {
|
||||
*dest = itr;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
Reference in New Issue
Block a user