reftable/stack: handle allocation failures in reftable_new_stack()
Handle allocation failures in `reftable_new_stack()`. 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
dce75e15ff
commit
5dbe266212
@ -56,10 +56,16 @@ static int reftable_fd_flush(void *arg)
|
|||||||
int reftable_new_stack(struct reftable_stack **dest, const char *dir,
|
int reftable_new_stack(struct reftable_stack **dest, const char *dir,
|
||||||
const struct reftable_write_options *_opts)
|
const struct reftable_write_options *_opts)
|
||||||
{
|
{
|
||||||
struct reftable_stack *p = reftable_calloc(1, sizeof(*p));
|
|
||||||
struct strbuf list_file_name = STRBUF_INIT;
|
struct strbuf list_file_name = STRBUF_INIT;
|
||||||
struct reftable_write_options opts = {0};
|
struct reftable_write_options opts = { 0 };
|
||||||
int err = 0;
|
struct reftable_stack *p;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
p = reftable_calloc(1, sizeof(*p));
|
||||||
|
if (!p) {
|
||||||
|
err = REFTABLE_OUT_OF_MEMORY_ERROR;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
if (_opts)
|
if (_opts)
|
||||||
opts = *_opts;
|
opts = *_opts;
|
||||||
@ -74,15 +80,23 @@ int reftable_new_stack(struct reftable_stack **dest, const char *dir,
|
|||||||
|
|
||||||
p->list_file = strbuf_detach(&list_file_name, NULL);
|
p->list_file = strbuf_detach(&list_file_name, NULL);
|
||||||
p->list_fd = -1;
|
p->list_fd = -1;
|
||||||
p->reftable_dir = xstrdup(dir);
|
|
||||||
p->opts = opts;
|
p->opts = opts;
|
||||||
|
p->reftable_dir = reftable_strdup(dir);
|
||||||
|
if (!p->reftable_dir) {
|
||||||
|
err = REFTABLE_OUT_OF_MEMORY_ERROR;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
err = reftable_stack_reload_maybe_reuse(p, 1);
|
err = reftable_stack_reload_maybe_reuse(p, 1);
|
||||||
if (err < 0) {
|
if (err < 0)
|
||||||
|
goto out;
|
||||||
|
|
||||||
|
*dest = p;
|
||||||
|
err = 0;
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (err < 0)
|
||||||
reftable_stack_destroy(p);
|
reftable_stack_destroy(p);
|
||||||
} else {
|
|
||||||
*dest = p;
|
|
||||||
}
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -171,6 +185,10 @@ void reftable_stack_destroy(struct reftable_stack *st)
|
|||||||
{
|
{
|
||||||
char **names = NULL;
|
char **names = NULL;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
if (!st)
|
||||||
|
return;
|
||||||
|
|
||||||
if (st->merged) {
|
if (st->merged) {
|
||||||
reftable_merged_table_free(st->merged);
|
reftable_merged_table_free(st->merged);
|
||||||
st->merged = NULL;
|
st->merged = NULL;
|
||||||
|
Reference in New Issue
Block a user