From 6cb2469058cfad0eb69d84ca33dfb82aedaabcf4 Mon Sep 17 00:00:00 2001 From: Stephan Bosch Date: Sat, 17 Feb 2018 15:08:44 +0100 Subject: [PATCH] lib-http: client: Hold reference to the connection while sending the next request. Subsequent changes may cause the connection to be destroyed while sending. --- src/lib-http/http-client-connection.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib-http/http-client-connection.c b/src/lib-http/http-client-connection.c index 777152f112..260822bf4b 100644 --- a/src/lib-http/http-client-connection.c +++ b/src/lib-http/http-client-connection.c @@ -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) -- 2.47.3