reftable/basics: handle allocation failures in parse_names()

Handle allocation failures in `parse_names()` by returning `NULL` in
case any allocation fails. While at it, refactor the function to return
the array directly instead of assigning it to an out-pointer.

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:55:38 +02:00
committed by Junio C Hamano
parent 6593e147d3
commit eef7bcdafe
4 changed files with 33 additions and 13 deletions

View File

@ -108,7 +108,11 @@ static int fd_read_lines(int fd, char ***namesp)
}
buf[size] = 0;
parse_names(buf, size, namesp);
*namesp = parse_names(buf, size);
if (!*namesp) {
err = REFTABLE_OUT_OF_MEMORY_ERROR;
goto done;
}
done:
reftable_free(buf);