]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dict: Fix client connection reference counting
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 10 May 2019 14:44:04 +0000 (17:44 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Mon, 13 May 2019 08:57:00 +0000 (08:57 +0000)
If the client disconnected while commands were still running, the destroy
callback could have been called multiple times.

Broken by 2ff2da52146609f4459bd0f7fd603e13400cb85e

Fixes:
Panic: file dict-connection.c: line 149 (dict_connection_unref): assertion failed: (array_count(&conn->cmds) == 0)

src/dict/dict-connection.c
src/dict/dict-connection.h

index a9f38f245eb0475d7dddcc686730ded28d228a66..0ed046f6f427849cc3a9485e952fc1c9a266ba23 100644 (file)
@@ -217,6 +217,14 @@ void dict_connection_unref_safe(struct dict_connection *conn)
 static void dict_connection_destroy(struct connection *_conn)
 {
        struct dict_connection *conn = container_of(_conn, struct dict_connection, conn);
+
+       /* If there are commands still running, we delay disconnecting can may
+          come back here. Track this so we unreference the connection only
+          once. */
+       if (conn->destroyed)
+               return;
+       conn->destroyed = TRUE;
+
        /* the connection is closed, but there may still be commands left
           running. finish them, even if the calling client can't be notified
           about whether they succeeded (clients may not even care).
index 3eba772fe2b85f4a50ea17a7ff682dc522536124..a07b64b7addc1080f6c496f055a12475133c9ff9 100644 (file)
@@ -28,6 +28,8 @@ struct dict_connection {
        ARRAY(struct dict_connection_transaction) transactions;
        ARRAY(struct dict_connection_cmd *) cmds;
        unsigned int async_id_counter;
+
+       bool destroyed;
 };
 
 struct master_service_connection;