From b474a7925468cb10cc3894d10f2c09a77d31d11f Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Sun, 22 Nov 2026 18:09:33 +0100 Subject: utils: Handle malloc() failure in fdlist_create() Free any partial allocation and start with an empty list instead of leaving NULL pointers with a non-zero capacity. fdlist_add() grows the list on first use. --- src/utils.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/utils.c b/src/utils.c index ec77234..f746608 100644 --- a/src/utils.c +++ b/src/utils.c @@ -46,6 +46,15 @@ void fdlist_create(struct fdlist *list) list->capacity = 4; list->owners = malloc(sizeof(*list->owners) * list->capacity); list->fds = malloc(sizeof(*list->fds) * list->capacity); + if (!list->owners || !list->fds) { + util_error("%s: out of memory", __func__); + // start empty; fdlist_add() will try to allocate on first use + free(list->owners); + free(list->fds); + list->owners = NULL; + list->fds = NULL; + list->capacity = 0; + } } void fdlist_add(struct fdlist *list, enum fdowner owner, int fd, short events) { -- cgit v1.1-32-gdbae