]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: client: Hold reference to the connection while sending the next request.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sat, 17 Feb 2018 14:08:44 +0000 (15:08 +0100)
committerStephan Bosch <stephan.bosch@dovecot.fi>
Sat, 17 Feb 2018 14:49:41 +0000 (15:49 +0100)
Subsequent changes may cause the connection to be destroyed while sending.

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

index 777152f11289ffb3ff350578a32d42c6482694ab..260822bf4bff7c6746aadcd9bc4b9f6f5d9c168e 100644 (file)
@@ -596,6 +596,7 @@ http_client_connection_continue_timeout(struct http_client_connection *conn)
 
 int http_client_connection_next_request(struct http_client_connection *conn)
 {
+       struct http_client_connection *tmp_conn;
        struct http_client_peer *peer = conn->peer;
        struct http_client_peer_shared *pshared = conn->ppool->peer;
        struct http_client_request *req = NULL;
@@ -631,7 +632,10 @@ int http_client_connection_next_request(struct http_client_connection *conn)
        e_debug(conn->event, "Claimed request %s",
                http_client_request_label(req));
 
-       if (http_client_request_send(req, pipelined) < 0)
+       tmp_conn = conn;
+       http_client_connection_ref(tmp_conn);
+       ret = http_client_request_send(req, pipelined);
+       if (!http_client_connection_unref(&tmp_conn) || ret < 0)
                return -1;
 
        if (req->connect_tunnel)