changeset 19732:535b6ed4d9ea

lib-http: server: Make sure that any pending request is aborted and destroyed before connection FDs are closed. This way, any payload io struct created from the request callback can be freed before the associated FD becomes invalid. This would cause an assert failure otherwise.
author Stephan Bosch <stephan@rename-it.nl>
date Mon, 08 Feb 2016 22:55:09 +0100
parents e7c075618c6d
children cf333b33c3ef
files src/lib-http/http-server-connection.c
diffstat 1 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-http/http-server-connection.c	Mon Feb 08 22:53:50 2016 +0100
+++ b/src/lib-http/http-server-connection.c	Mon Feb 08 22:55:09 2016 +0100
@@ -861,6 +861,8 @@
 http_server_connection_disconnect(struct http_server_connection *conn,
 	const char *reason)
 {
+	struct http_server_request *req, *req_next;
+
 	if (conn->closed)
 		return;
 
@@ -873,6 +875,14 @@
 	/* preserve statistics */
 	http_server_connection_update_stats(conn);
 
+	/* drop all requests before connection is closed */
+	req = conn->request_queue_head;
+	while (req != NULL) {
+		req_next = req->next;
+		http_server_request_abort(&req);
+		req = req_next;
+	}
+
 	if (conn->to_input != NULL)
 		timeout_remove(&conn->to_input);
 
@@ -899,7 +909,6 @@
 void http_server_connection_unref(struct http_server_connection **_conn)
 {
 	struct http_server_connection *conn = *_conn;
-	struct http_server_request *req, *req_next;
 
 	i_assert(conn->refcount > 0);
 	if (--conn->refcount > 0)
@@ -909,13 +918,6 @@
 
 	http_server_connection_debug(conn, "Connection destroy");
 
-	req = conn->request_queue_head;
-	while (req != NULL) {
-		req_next = req->next;
-		http_server_request_abort(&req);
-		req = req_next;
-	}
-
 	if (conn->ssl_iostream != NULL)
 		ssl_iostream_unref(&conn->ssl_iostream);
 	connection_deinit(&conn->conn);