From: Stefan Eissing Date: Mon, 12 Oct 2026 07:40:45 +0200 Subject: [PATCH] multi: adjust the cleanup order in multi_done Closes #23370 Backported-by: Samuel Henrique * lib/multi.c: 8.14.1's multi_done() detaches the connection, prunes the DNS cache and returns the connection to the pool inside Curl_cpool_do_locked()/multi_done_locked() instead of upstream's if(conn) block, so get the same order by moving the existing calls: - Curl_req_done() before Curl_conn_ev_data_done(); - Curl_conn_ev_data_done() right before Curl_cpool_do_locked(); - process_pending_handles(), 8.14.1's name for upstream's multi_schedule_pending(), after Curl_cpool_do_locked(). * lib/multi.c: keep calling Curl_conn_ev_data_done() and process_pending_handles() unconditionally, without upstream's if(conn) and if(data->multi) checks, as 8.14.1's multi_done() always has a connection and a multi handle. --- lib/multi.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/multi.c b/lib/multi.c index 64eb1ae85..1d193250f 100644 --- a/lib/multi.c +++ b/lib/multi.c @@ -642,19 +642,20 @@ static CURLcode multi_done(struct Curl_easy *data, if(r2 && !result) result = r2; - /* Inform connection filters that this transfer is done */ - Curl_conn_ev_data_done(data, premature); - - process_pending_handles(data->multi); /* connection / multiplex */ - if(!result) result = Curl_req_done(&data->req, data, premature); + /* Inform connection filters that this transfer is done and they + * need to give up any references to `data`. */ + Curl_conn_ev_data_done(data, premature); + /* Under the potential connection pool's share lock, decide what to * do with the transfer's connection. */ mdctx.premature = premature; Curl_cpool_do_locked(data, data->conn, multi_done_locked, &mdctx); + process_pending_handles(data->multi); /* connection / multiplex */ + /* flush the netrc cache */ Curl_netrc_cleanup(&data->state.netrc); return result;