mirror of
https://github.com/git/git
synced 2024-11-05 01:58:18 +00:00
reftable/stack: handle allocation failures on reload
Handle allocation failures in `reftable_stack_reload_once()`. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
0a8372f509
commit
dce75e15ff
1 changed files with 25 additions and 9 deletions
|
@ -214,13 +214,13 @@ void reftable_stack_destroy(struct reftable_stack *st)
|
|||
}
|
||||
|
||||
static struct reftable_reader **stack_copy_readers(struct reftable_stack *st,
|
||||
int cur_len)
|
||||
size_t cur_len)
|
||||
{
|
||||
struct reftable_reader **cur = reftable_calloc(cur_len, sizeof(*cur));
|
||||
int i = 0;
|
||||
for (i = 0; i < cur_len; i++) {
|
||||
if (!cur)
|
||||
return NULL;
|
||||
for (size_t i = 0; i < cur_len; i++)
|
||||
cur[i] = st->readers[i];
|
||||
}
|
||||
return cur;
|
||||
}
|
||||
|
||||
|
@ -229,18 +229,30 @@ static int reftable_stack_reload_once(struct reftable_stack *st,
|
|||
int reuse_open)
|
||||
{
|
||||
size_t cur_len = !st->merged ? 0 : st->merged->readers_len;
|
||||
struct reftable_reader **cur = stack_copy_readers(st, cur_len);
|
||||
struct reftable_reader **cur;
|
||||
struct reftable_reader **reused = NULL;
|
||||
size_t reused_len = 0, reused_alloc = 0;
|
||||
size_t names_len = names_length(names);
|
||||
struct reftable_reader **new_readers =
|
||||
reftable_calloc(names_len, sizeof(*new_readers));
|
||||
struct reftable_reader **new_readers;
|
||||
size_t reused_len = 0, reused_alloc = 0, names_len;
|
||||
size_t new_readers_len = 0;
|
||||
struct reftable_merged_table *new_merged = NULL;
|
||||
struct strbuf table_path = STRBUF_INIT;
|
||||
int err = 0;
|
||||
size_t i;
|
||||
|
||||
cur = stack_copy_readers(st, cur_len);
|
||||
if (!cur) {
|
||||
err = REFTABLE_OUT_OF_MEMORY_ERROR;
|
||||
goto done;
|
||||
}
|
||||
|
||||
names_len = names_length(names);
|
||||
|
||||
new_readers = reftable_calloc(names_len, sizeof(*new_readers));
|
||||
if (!new_readers) {
|
||||
err = REFTABLE_OUT_OF_MEMORY_ERROR;
|
||||
goto done;
|
||||
}
|
||||
|
||||
while (*names) {
|
||||
struct reftable_reader *rd = NULL;
|
||||
const char *name = *names++;
|
||||
|
@ -261,6 +273,10 @@ static int reftable_stack_reload_once(struct reftable_stack *st,
|
|||
* do by bumping their refcount.
|
||||
*/
|
||||
REFTABLE_ALLOC_GROW(reused, reused_len + 1, reused_alloc);
|
||||
if (!reused) {
|
||||
err = REFTABLE_OUT_OF_MEMORY_ERROR;
|
||||
goto done;
|
||||
}
|
||||
reused[reused_len++] = rd;
|
||||
reftable_reader_incref(rd);
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue