From 1fbe7d9345ab81a21301d1481ac8861837e2d8b9 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Wed, 4 Mar 2020 20:39:21 +0200 Subject: [PATCH] dict-client: Fix panic if iteration is deinitialized before it has finished Fixes: Panic: BUG: No IOs or timeouts set. Not waiting for infinity. --- src/lib-dict/dict-client.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/lib-dict/dict-client.c b/src/lib-dict/dict-client.c index aa728bdecb..2439d93ea3 100644 --- a/src/lib-dict/dict-client.c +++ b/src/lib-dict/dict-client.c @@ -170,6 +170,15 @@ static bool client_dict_cmd_unref(struct client_dict_cmd *cmd) return FALSE; } +static void dict_client_stop_wait(struct client_dict *dict) +{ + if (dict->prev_ioloop != NULL) { + current_ioloop = dict->ioloop; + /* stop client_dict_wait() */ + io_loop_stop(dict->ioloop); + } +} + static void dict_pre_api_callback(struct client_dict *dict) { if (dict->prev_ioloop != NULL) { @@ -182,11 +191,7 @@ static void dict_pre_api_callback(struct client_dict *dict) static void dict_post_api_callback(struct client_dict *dict) { - if (dict->prev_ioloop != NULL) { - current_ioloop = dict->ioloop; - /* stop client_dict_wait() */ - io_loop_stop(dict->ioloop); - } + dict_client_stop_wait(dict); } static bool @@ -1057,7 +1062,9 @@ client_dict_iter_api_callback(struct client_dict_iterate_context *ctx, struct client_dict *dict = cmd->dict; if (ctx->deinit) { - /* iterator was already deinitialized */ + /* Iterator was already deinitialized. Stop if we're in + client_dict_wait(). */ + dict_client_stop_wait(dict); return; } if (ctx->finished) { -- 2.47.3