From: Timo Sirainen Date: Wed, 21 Apr 2021 13:55:57 +0000 (+0300) Subject: lib: event_pop_global() - Assert-crash if trying to pop ioloop context's global root... X-Git-Tag: 2.3.18~363 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2bba7f1f347ebdd23c74cf42c97b5d8399afc04c;p=thirdparty%2Fdovecot%2Fcore.git lib: event_pop_global() - Assert-crash if trying to pop ioloop context's global root event This makes it easier to debug bugs. --- diff --git a/src/lib/ioloop-private.h b/src/lib/ioloop-private.h index b7b2aafece..799ca4d6d5 100644 --- a/src/lib/ioloop-private.h +++ b/src/lib/ioloop-private.h @@ -124,4 +124,6 @@ void io_loop_handler_deinit(struct ioloop *ioloop); void io_loop_notify_remove(struct io *io); void io_loop_notify_handler_deinit(struct ioloop *ioloop); +struct event *io_loop_get_active_global_root(void); + #endif diff --git a/src/lib/ioloop.c b/src/lib/ioloop.c index c1db61a2f2..39b171329a 100644 --- a/src/lib/ioloop.c +++ b/src/lib/ioloop.c @@ -1374,3 +1374,12 @@ uint64_t io_wait_timer_get_usecs(struct io_wait_timer *timer) { return timer->usecs; } + +struct event *io_loop_get_active_global_root(void) +{ + if (current_ioloop == NULL) + return NULL; + if (current_ioloop->cur_ctx == NULL) + return NULL; + return current_ioloop->cur_ctx->root_global_event; +} diff --git a/src/lib/lib-event.c b/src/lib/lib-event.c index f1c45cbe5c..809914af4e 100644 --- a/src/lib/lib-event.c +++ b/src/lib/lib-event.c @@ -8,7 +8,7 @@ #include "time-util.h" #include "str.h" #include "strescape.h" -#include "ioloop.h" +#include "ioloop-private.h" enum event_code { EVENT_CODE_ALWAYS_LOG_SOURCE = 'a', @@ -499,6 +499,10 @@ struct event *event_pop_global(struct event *event) { i_assert(event != NULL); i_assert(event == current_global_event); + /* If the active context's root event is popped, we'll assert-crash + later on when deactivating the context and the root event no longer + exists. */ + i_assert(event != io_loop_get_active_global_root()); if (!array_is_created(&global_event_stack) || array_count(&global_event_stack) == 0)