From: Marco Bettini Date: Tue, 7 May 2024 13:34:48 +0000 (+0000) Subject: lib-imap-client: imapc_command_abort() - Remove command from connection's arrays... X-Git-Tag: 2.4.0~1662 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=17db6fa52b9e62399f7de3fe53bf991ebf3f978e;p=thirdparty%2Fdovecot%2Fcore.git lib-imap-client: imapc_command_abort() - Remove command from connection's arrays before freeing it Broken by db8a542f3d9 --- diff --git a/src/lib-imap-client/imapc-connection.c b/src/lib-imap-client/imapc-connection.c index 15577e9653..5ebdb2eb40 100644 --- a/src/lib-imap-client/imapc-connection.c +++ b/src/lib-imap-client/imapc-connection.c @@ -2011,11 +2011,34 @@ const char *imapc_command_get_tag(struct imapc_command *cmd) return t_strdup_printf("%u", cmd->tag); } +static bool imapc_cmd_remove(ARRAY_TYPE(imapc_command) *entries, + struct imapc_command *cmd) +{ + if (array_is_empty(entries)) + return FALSE; + + unsigned int count; + struct imapc_command *const *items = array_get(entries, &count); + for (unsigned int ndx = 0; ndx < count; ndx++) { + if (items[ndx] == cmd) { + array_delete(entries, ndx, 1); + return TRUE; + } + } + return FALSE; +} + void imapc_command_abort(struct imapc_command **_cmd) { struct imapc_command *cmd = *_cmd; + if (cmd == NULL) + return; *_cmd = NULL; + + if (!imapc_cmd_remove(&cmd->conn->cmd_send_queue, cmd)) + (void)imapc_cmd_remove(&cmd->conn->cmd_wait_list, cmd); + imapc_command_free(cmd); }