From fdbed6409b116cca8f1e934b55dcbe77022269ea Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 7 Nov 2014 15:08:09 +0000 Subject: [PATCH] Stop use-after-free in event loop termination. --- src/libserver/worker_util.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c index 0c304feb0..17c5ba872 100644 --- a/src/libserver/worker_util.c +++ b/src/libserver/worker_util.c @@ -64,13 +64,12 @@ rspamd_worker_usr2_handler (gint fd, short what, void *arg) tv.tv_sec = SOFT_SHUTDOWN_TIME; tv.tv_usec = 0; wanna_die = 1; - rspamd_worker_stop_accept (sigh->worker); msg_info ("worker's shutdown is pending in %d sec", SOFT_SHUTDOWN_TIME); event_base_loopexit (sigh->base, &tv); - } - - if (sigh->post_handler) { - sigh->post_handler (sigh->handler_data); + if (sigh->post_handler) { + sigh->post_handler (sigh->handler_data); + } + rspamd_worker_stop_accept (sigh->worker); } } @@ -102,14 +101,14 @@ rspamd_worker_term_handler (gint fd, short what, void *arg) wanna_die = 1; tv.tv_sec = 0; tv.tv_usec = 0; + if (sigh->post_handler) { + sigh->post_handler (sigh->handler_data); + } event_base_loopexit (sigh->base, &tv); #ifdef WITH_GPERF_TOOLS ProfilerStop (); #endif - } - - if (sigh->post_handler) { - sigh->post_handler (sigh->handler_data); + rspamd_worker_stop_accept (sigh->worker); } } -- 2.39.5