changeset 22828:b562bf4b2513

doveadm-server: http: Fixed crash occurring when disconnecting a client at server deinit.
author Stephan Bosch <stephan.bosch@dovecot.fi>
date Sun, 18 Jun 2017 19:55:23 +0200
parents ce305d3d9b52
children 89547df99d4a
files src/doveadm/client-connection-http.c src/doveadm/client-connection-private.h src/doveadm/client-connection.c src/doveadm/client-connection.h
diffstat 4 files changed, 34 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/client-connection-http.c	Thu Feb 08 13:04:48 2018 +0200
+++ b/src/doveadm/client-connection-http.c	Sun Jun 18 19:55:23 2017 +0200
@@ -105,6 +105,7 @@
 	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 @@
 	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);
 }
 
--- a/src/doveadm/client-connection-private.h	Thu Feb 08 13:04:48 2018 +0200
+++ b/src/doveadm/client-connection-private.h	Sun Jun 18 19:55:23 2017 +0200
@@ -11,6 +11,8 @@
 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);
 
--- a/src/doveadm/client-connection.c	Thu Feb 08 13:04:48 2018 +0200
+++ b/src/doveadm/client-connection.c	Sun Jun 18 19:55:23 2017 +0200
@@ -689,6 +689,9 @@
 
 	doveadm_print_deinit();
 
+	if (conn->http)
+		client_connection_destroy_http(conn);
+
 	if (conn->ssl_iostream != NULL)
 		ssl_iostream_destroy(&conn->ssl_iostream);
 
--- a/src/doveadm/client-connection.h	Thu Feb 08 13:04:48 2018 +0200
+++ b/src/doveadm/client-connection.h	Sun Jun 18 19:55:23 2017 +0200
@@ -25,6 +25,7 @@
 	unsigned int authenticated:1;
 	unsigned int io_setup:1;
 	unsigned int use_multiplex:1;
+	unsigned int http:1;
 };
 
 struct client_connection *