From f319c1ff836f213a2db634c417008e7ac5d3de6f Mon Sep 17 00:00:00 2001 From: Brad House Date: Sun, 14 Jul 2024 08:57:11 -0400 Subject: [PATCH] kqueue: fix allocation size when socket count > 8 --- src/lib/ares_event_kqueue.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib/ares_event_kqueue.c b/src/lib/ares_event_kqueue.c index 944c4b00..017c05f8 100644 --- a/src/lib/ares_event_kqueue.c +++ b/src/lib/ares_event_kqueue.c @@ -95,7 +95,7 @@ static ares_bool_t ares_evsys_kqueue_init(ares_event_thread_t *e) kq->nchanges_alloc = 8; kq->changelist = - ares_malloc_zero(sizeof(*kq->changelist) * kq->nchanges_alloc); + ares_malloc_zero(kq->nchanges_alloc * sizeof(*kq->changelist)); if (kq->changelist == NULL) { ares_evsys_kqueue_destroy(e); return ARES_FALSE; @@ -125,8 +125,11 @@ static void ares_evsys_kqueue_enqueue(ares_evsys_kqueue_t *kq, int fd, if (kq->nchanges > kq->nchanges_alloc) { kq->nchanges_alloc <<= 1; - kq->changelist = ares_realloc_zero(kq->changelist, kq->nchanges_alloc >> 1, - kq->nchanges_alloc); + kq->changelist = ares_realloc_zero( + kq->changelist, + (kq->nchanges_alloc >> 1) * sizeof(*kq->changelist), + kq->nchanges_alloc * sizeof(*kq->changelist) + ); } EV_SET(&kq->changelist[idx], fd, filter, flags, 0, 0, 0);