From: Timo Sirainen Date: Mon, 8 Jan 2024 14:25:33 +0000 (-0500) Subject: lib: ioloop-kqueue - Fix memory leak when ioloop stops before all IO callbacks are... X-Git-Tag: 2.4.0~1799 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dfcdac4583afc87b8cd03a9ad8124f1fb679a2ea;p=thirdparty%2Fdovecot%2Fcore.git lib: ioloop-kqueue - Fix memory leak when ioloop stops before all IO callbacks are called Broken by 720a6e0e67c3f04dcfee4c80b34f0291c7217cfa --- diff --git a/src/lib/ioloop-kqueue.c b/src/lib/ioloop-kqueue.c index 0af05c846c..87cd8a4546 100644 --- a/src/lib/ioloop-kqueue.c +++ b/src/lib/ioloop-kqueue.c @@ -163,9 +163,7 @@ void io_loop_handler_run_internal(struct ioloop *ioloop) /* execute timeout handlers */ io_loop_handle_timeouts(ioloop); - if (!ioloop->running) - return; - + bool call_callbacks = ioloop->running; for (i = 0; i < ret; i++) { /* io_loop_handle_add() may cause events array reallocation, so we have use array_idx() */ @@ -173,10 +171,14 @@ void io_loop_handler_run_internal(struct ioloop *ioloop) io = (void *)event->udata; /* callback is NULL if io_remove() was already called */ - if (io->io.callback != NULL) { + if (io->io.callback != NULL && call_callbacks) { io_loop_call_io(&io->io); - if (!ioloop->running) - break; + if (!ioloop->running) { + /* Don't call any further callbacks, but the + rest of the IOs still need to be + unreferenced. */ + call_callbacks = FALSE; + } } i_assert(io->refcount > 0);