]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-smtp: server: Drop pending commands and transaction at disconnect rather than...
authorStephan Bosch <stephan.bosch@dovecot.fi>
Wed, 12 Sep 2018 19:21:09 +0000 (21:21 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Tue, 9 Oct 2018 06:41:17 +0000 (06:41 +0000)
This makes sure the conn_trans_free() connection callback is called before
th conn_disconnect() callback. This makes more sense than the other way around,
which instead would be a likely cause for mishaps causing segfaults and the
like.

src/lib-smtp/smtp-server-connection.c

index 9076d8f2d4ff065e74918ff0f52eb84315169e28..00505332a8f07075229f0c5d244b0765cbfe3c05 100644 (file)
@@ -1072,6 +1072,8 @@ static void
 smtp_server_connection_disconnect(struct smtp_server_connection *conn,
                                  const char *reason)
 {
+       struct smtp_server_command *cmd, *cmd_next;
+
        if (conn->disconnected)
                return;
        conn->disconnected = TRUE;
@@ -1084,6 +1086,17 @@ smtp_server_connection_disconnect(struct smtp_server_connection *conn,
        /* preserve statistics */
        smtp_server_connection_update_stats(conn);
 
+       /* drop transaction */
+       smtp_server_connection_reset_state(conn);
+
+       /* clear command queue */
+       cmd = conn->command_queue_head;
+       while (cmd != NULL) {
+               cmd_next = cmd->next;
+               smtp_server_command_abort(&cmd);
+               cmd = cmd_next;
+       }
+
        smtp_server_connection_timeout_stop(conn);
        if (conn->conn.output != NULL)
                o_stream_uncork(conn->conn.output);
@@ -1114,7 +1127,6 @@ smtp_server_connection_disconnect(struct smtp_server_connection *conn,
 bool smtp_server_connection_unref(struct smtp_server_connection **_conn)
 {
        struct smtp_server_connection *conn = *_conn;
-       struct smtp_server_command *cmd, *cmd_next;
 
        *_conn = NULL;
 
@@ -1126,17 +1138,6 @@ bool smtp_server_connection_unref(struct smtp_server_connection **_conn)
 
        smtp_server_connection_debug(conn, "Connection destroy");
 
-       /* drop transaction */
-       smtp_server_connection_reset_state(conn);
-
-       /* clear command queue */
-       cmd = conn->command_queue_head;
-       while (cmd != NULL) {
-               cmd_next = cmd->next;
-               smtp_server_command_abort(&cmd);
-               cmd = cmd_next;
-       }
-
        if (conn->callbacks != NULL &&
                conn->callbacks->conn_destroy != NULL)
                conn->callbacks->conn_destroy(conn->context);