]> 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 <tss@dovecot.fi>
Wed, 6 Sep 2017 14:29:38 +0000 (17:29 +0300)
src/doveadm/client-connection-http.c
src/doveadm/client-connection-private.h
src/doveadm/client-connection.c
src/doveadm/client-connection.h

index 820dbf85411a082591d019a6756853312c5f9579..d12a8aabfbaed7299633ab2893343518985c9cb6 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 2e886835c20f7af60bc1c314679d4fb73148a620..d98c6564d3901e2d875980ad4c73be19132ee44c 100644 (file)
@@ -563,6 +563,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 1f2fc53b09e2cef8ca132e3d2a8d079233eacd39..4dae6477f9584748f4eaba4a4111f9b75bc7aab4 100644 (file)
@@ -18,6 +18,7 @@ struct client_connection {
 
        bool handshaked:1;
        bool authenticated:1;
+       bool http:1;
 };
 
 struct client_connection *