]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
doveadm-server: http: Fixed crash occurring when disconnecting a client at server...
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 18 Jun 2017 17:55:23 +0000 (19:55 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 12 Feb 2018 14:21:23 +0000 (16:21 +0200)
src/doveadm/client-connection-http.c
src/doveadm/client-connection-private.h
src/doveadm/client-connection.c
src/doveadm/client-connection.h

index 754a06dc8fbf98cb9652caca49b5d1f201b19b9f..4d30c95d4efd3f9f40a34d6cbbfcaaf5973060d9 100644 (file)
@@ -105,6 +105,7 @@ client_connection_create_http(int fd, bool ssl)
        pool = pool_alloconly_create("doveadm client", 1024*16);
        conn = p_new(pool, struct client_connection_http, 1);
        conn->client.pool = pool;
+       conn->client.http = TRUE;
 
        if (client_connection_init(&conn->client, fd) < 0)
                return NULL;
@@ -115,10 +116,35 @@ client_connection_create_http(int fd, bool ssl)
        return &conn->client;
 }
 
+void client_connection_destroy_http(struct client_connection *conn)
+{
+       struct client_connection_http *hconn =
+               (struct client_connection_http *)conn;
+
+       if (hconn->http_client != NULL) {
+               /* We're not in the lib-http/server's connection destroy callback. */
+               http_server_connection_close(&hconn->http_client,
+                       "Server shutting down");
+       }
+}
+
 static void
-doveadm_http_server_connection_destroy(void *context, const char *reason ATTR_UNUSED)
+doveadm_http_server_connection_destroy(void *context,
+       const char *reason ATTR_UNUSED)
 {
-       struct client_connection *conn = context;
+       struct client_connection_http *hconn =
+               (struct client_connection_http *)context;
+       struct client_connection *conn = &hconn->client;
+
+       if (hconn->http_client == NULL) {
+               /* already destroying client directly */
+               return;
+       }
+
+       /* HTTP connection is destroyed already now */
+       hconn->http_client = NULL;
+
+       /* destroy the connection itself */
        client_connection_destroy(&conn);
 }
 
index 928158788e348ea7287a6dd8ac6c8d094a42a21b..fefadfc6b39d4d99d587f7eb977b38031b547320 100644 (file)
@@ -11,6 +11,8 @@ int client_connection_init(struct client_connection *conn, int fd);
 void client_connection_set_proctitle(struct client_connection *conn,
                                     const char *text);
 
+void client_connection_destroy_http(struct client_connection *conn);
+
 void doveadm_http_server_init(void);
 void doveadm_http_server_deinit(void);
 
index 7125436ba889582afac8a0a45d37d694bfe488ac..91b95fdf75e817d81ae26980807d9195788c7f1f 100644 (file)
@@ -689,6 +689,9 @@ void client_connection_destroy(struct client_connection **_conn)
 
        doveadm_print_deinit();
 
+       if (conn->http)
+               client_connection_destroy_http(conn);
+
        if (conn->ssl_iostream != NULL)
                ssl_iostream_destroy(&conn->ssl_iostream);
 
index b0e087b109ba12bb1ddc2772788d724126ccd315..f7b15b0d257a7bcc34a9a9b97616a48d4b870f40 100644 (file)
@@ -25,6 +25,7 @@ struct client_connection {
        unsigned int authenticated:1;
        unsigned int io_setup:1;
        unsigned int use_multiplex:1;
+       unsigned int http:1;
 };
 
 struct client_connection *