]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-imap-client: imapc_command_abort() - Remove command from connection's arrays...
authorMarco Bettini <marco.bettini@open-xchange.com>
Tue, 7 May 2024 13:34:48 +0000 (13:34 +0000)
committerMarco Bettini <marco.bettini@open-xchange.com>
Fri, 10 May 2024 12:37:06 +0000 (12:37 +0000)
Broken by db8a542f3d9

src/lib-imap-client/imapc-connection.c

index 15577e965340405e065ed91b72e120f2e1d20610..5ebdb2eb40b21b23fcd2cb630b93e5f096928db9 100644 (file)
@@ -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);
 }