]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lmtp: Simplify client_destroy() handling
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 2 Mar 2021 14:40:48 +0000 (16:40 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 11 Mar 2021 11:19:09 +0000 (11:19 +0000)
This is similar to the earlier submission commit.

src/lmtp/lmtp-client.c
src/lmtp/lmtp-client.h

index 196ee6d9454f73eab2d364e02bcc69a421f98757..2757c803a6be4af8a81bb1816c6d620b3618c0c8 100644 (file)
@@ -250,24 +250,24 @@ void client_state_reset(struct client *client)
        p_clear(client->state_pool);
 }
 
-void client_destroy(struct client *client, const char *enh_code,
+void client_destroy(struct client **_client, const char *enh_code,
                    const char *reason)
 {
-       client->v.destroy(client, enh_code, reason);
+       struct client *client = *_client;
+
+       *_client = NULL;
+
+       smtp_server_connection_terminate(&client->conn,
+               (enh_code == NULL ? "4.0.0" : enh_code), reason);
 }
 
 static void
-client_default_destroy(struct client *client, const char *enh_code,
-                      const char *reason)
+client_default_destroy(struct client *client)
 {
        if (client->destroyed)
                return;
        client->destroyed = TRUE;
 
-       if (client->conn != NULL) {
-               smtp_server_connection_terminate(&client->conn,
-                       (enh_code == NULL ? "4.0.0" : enh_code), reason);
-       }
        clients_count--;
        DLLIST_REMOVE(&clients, client);
 
@@ -371,7 +371,7 @@ static void client_connection_free(void *context)
 {
        struct client *client = (struct client *)context;
 
-       client_destroy(client, NULL, NULL);
+       client->v.destroy(client);
 }
 
 static bool client_connection_is_trusted(void *context)
@@ -401,7 +401,8 @@ static bool client_connection_is_trusted(void *context)
 void clients_destroy(void)
 {
        while (clients != NULL) {
-               client_destroy(clients, "4.3.2", "Shutting down");
+               struct client *client = clients;
+               client_destroy(&client, "4.3.2", "Shutting down");
        }
 }
 
index b3c463dd90254e7b4f65ae4b4c716c28c3e95111..0e7d963e4392db5d169d53de2502783a2f86f2ad 100644 (file)
@@ -44,8 +44,7 @@ struct client_state {
 };
 
 struct lmtp_client_vfuncs {
-       void (*destroy)(struct client *client, const char *enh_code,
-                       const char *reason);
+       void (*destroy)(struct client *client);
 
        void (*trans_start)(struct client *client,
                            struct smtp_server_transaction *trans);
@@ -114,7 +113,7 @@ extern struct lmtp_module_register lmtp_module_register;
 
 struct client *client_create(int fd_in, int fd_out,
                             const struct master_service_connection *conn);
-void client_destroy(struct client *client, const char *enh_code,
+void client_destroy(struct client **client, const char *enh_code,
                    const char *reason) ATTR_NULL(2, 3);
 
 void client_state_reset(struct client *client);