summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2026-11-22 18:09:33 +0100
committerGravatar Nikias Bassen2026-11-22 18:09:33 +0100
commitb474a7925468cb10cc3894d10f2c09a77d31d11f (patch)
treee458225081d11bf87b03432f89a869806fb2de44
parentda392d27f2d8938bf002093bb94dc60beba6afd8 (diff)
downloadusbmuxd-b474a7925468cb10cc3894d10f2c09a77d31d11f.tar.gz
usbmuxd-b474a7925468cb10cc3894d10f2c09a77d31d11f.tar.bz2
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.
-rw-r--r--src/utils.c9
1 files changed, 9 insertions, 0 deletions
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)
{