diff options
| author | 2026-11-22 18:09:33 +0100 | |
|---|---|---|
| committer | 2026-11-22 18:09:33 +0100 | |
| commit | b474a7925468cb10cc3894d10f2c09a77d31d11f (patch) | |
| tree | e458225081d11bf87b03432f89a869806fb2de44 /src/utils.c | |
| parent | da392d27f2d8938bf002093bb94dc60beba6afd8 (diff) | |
| download | usbmuxd-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.
Diffstat (limited to 'src/utils.c')
| -rw-r--r-- | src/utils.c | 9 |
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) { |
