cfilter: unlink and discard

Rewrite the code that removes a filter from the connection and discards
it. Always look at the connection, otherwise it will not work of the
filter is at the top of the chain.

Change QUIC filter setup code to always tear down the chain in
construction when an error occured.

HTTP proxy, do not remove the h1/h2 sub filter on close. Leave it to be
discarded with the connection. Avoids keeping an additional pointer that
might become dangling.

Triggered by a reported on a code bug in discard method.

Reported-by: Joshua Rogers
Closes #18596
This commit is contained in:
Stefan Eissing 2025-09-18 11:10:45 +02:00 committed by Daniel Stenberg
parent ca034e839c
commit 0f08211330
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
7 changed files with 54 additions and 85 deletions

View file

@ -297,16 +297,12 @@ void Curl_conn_cf_insert_after(struct Curl_cfilter *cf_at,
struct Curl_cfilter *cf_new);
/**
* Discard, e.g. remove and destroy `discard` iff
* it still is in the filter chain below `cf`. If `discard`
* is no longer found beneath `cf` return FALSE.
* if `destroy_always` is TRUE, will call `discard`s destroy
* function and free it even if not found in the subchain.
* Extract filter `*pcf` from its connection filter chain.
* Destroy `*pcf`, even if it was not part of the chain and NULL it.
* Returns TRUE of cf has been part of chain.
*/
bool Curl_conn_cf_discard_sub(struct Curl_cfilter *cf,
struct Curl_cfilter *discard,
struct Curl_easy *data,
bool destroy_always);
bool Curl_conn_cf_discard(struct Curl_cfilter **pcf,
struct Curl_easy *data);
/**
* Discard all cfilters starting with `*pcf` and clearing it afterwards.