url: call protocol handler's disconnect in Curl_conn_free

For the case when the connection struct is all setup, the protocol
handler allocates data in its setup_connection function, but the
connection struct is discarded again before used further because a
connection reuse is prefered. Then the handler's disconnect function was
not previously called, which then would lead to a memory leak.

I added test case 698 that reproduces the leak and the fix.

Reported-by: Philippe Antoine
Closes #16604
This commit is contained in:
Daniel Stenberg 2025-03-07 09:32:57 +01:00
parent 0d1e43af8d
commit f4831daa9b
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
3 changed files with 63 additions and 1 deletions

View file

@ -557,6 +557,10 @@ void Curl_conn_free(struct Curl_easy *data, struct connectdata *conn)
DEBUGASSERT(conn);
if(conn->handler && conn->handler->disconnect &&
!conn->bits.shutdown_handler)
conn->handler->disconnect(data, conn, TRUE);
for(i = 0; i < CURL_ARRAYSIZE(conn->cfilter); ++i) {
Curl_conn_cf_discard_all(data, conn, (int)i);
}