changeset 22983:f2f813d047c8

lib: io_loop_context_new() - deactivate old context Since it changes the current context, it needs to deactivate the old one.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Tue, 12 Dec 2017 01:02:27 +0200
parents 697e36c7feae
children d62b238d7d66
files src/lib/ioloop.c
diffstat 1 files changed, 6 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/ioloop.c	Tue Jun 05 15:31:20 2018 +0300
+++ b/src/lib/ioloop.c	Tue Dec 12 01:02:27 2017 +0200
@@ -834,8 +834,12 @@
 	ctx->ioloop = ioloop;
 	i_array_init(&ctx->callbacks, 4);
 
-	if (ioloop->cur_ctx != NULL)
-		io_loop_context_unref(&ioloop->cur_ctx);
+	if (ioloop->cur_ctx != NULL) {
+		io_loop_context_deactivate(ioloop->cur_ctx);
+		/* deactivation may remove the cur_ctx */
+		if (ioloop->cur_ctx != NULL)
+			io_loop_context_unref(&ioloop->cur_ctx);
+	}
 	ioloop->cur_ctx = ctx;
 	return ctx;
 }