From eef7bcdafe0037f14a96c564ace899342b9ed0fb Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Wed, 2 Oct 2024 12:55:38 +0200 Subject: 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 Signed-off-by: Junio C Hamano --- reftable/stack.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'reftable/stack.c') diff --git a/reftable/stack.c b/reftable/stack.c index ce0a35216b..498fae846d 100644 --- a/reftable/stack.c +++ b/reftable/stack.c @@ -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); -- cgit v1.2.3