]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: server: Make sure that any pending request is aborted and destroyed before...
authorStephan Bosch <stephan@rename-it.nl>
Mon, 8 Feb 2016 21:55:09 +0000 (22:55 +0100)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 10 Feb 2016 11:55:26 +0000 (13:55 +0200)
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.

src/lib-http/http-server-connection.c

index c183f3fe2e7602c13c3781273626f2ccacb5895d..2e9a56ad79a6e4aa7cafe26eb6f4ad66888a1416 100644 (file)
@@ -861,6 +861,8 @@ static void
 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 @@ http_server_connection_disconnect(struct http_server_connection *conn,
        /* 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 @@ http_server_connection_disconnect(struct http_server_connection *conn,
 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 @@ void http_server_connection_unref(struct http_server_connection **_conn)
 
        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);