From: Stefan Eissing Date: Tue, 29 Apr 2025 08:53:34 +0000 (+0200) Subject: meta data handling for easy/conn fixes X-Git-Tag: curl-8_14_0~178 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f0824d1ed73bbea0e74d9f35b8a3b7c5c04fd884;p=thirdparty%2Fcurl.git meta data handling for easy/conn fixes - return error when adding to hash fails - do not free passed in data, as ownership is taken by call Closes #17219 --- diff --git a/lib/doh.c b/lib/doh.c index 64fb54e33a..672842ba83 100644 --- a/lib/doh.c +++ b/lib/doh.c @@ -431,11 +431,10 @@ static CURLcode doh_probe_run(struct Curl_easy *data, doh->state.internal = TRUE; doh->master_mid = data->mid; /* master transfer of this one */ - if(Curl_meta_set(doh, CURL_EZM_DOH_PROBE, doh_req, doh_probe_dtor)) { - result = CURLE_OUT_OF_MEMORY; + result = Curl_meta_set(doh, CURL_EZM_DOH_PROBE, doh_req, doh_probe_dtor); + doh_req = NULL; /* call took ownership */ + if(result) goto error; - } - doh_req = NULL; /* DoH handles must not inherit private_data. The handles may be passed to the user via callbacks and the user will be able to identify them as diff --git a/lib/easy.c b/lib/easy.c index 7fc285f7b9..af913bffa2 100644 --- a/lib/easy.c +++ b/lib/easy.c @@ -1393,6 +1393,7 @@ CURLcode Curl_meta_set(struct Curl_easy *data, const char *key, if(!Curl_hash_add2(&data->meta_hash, CURL_UNCONST(key), strlen(key) + 1, meta_data, meta_dtor)) { meta_dtor(CURL_UNCONST(key), strlen(key) + 1, meta_data); + return CURLE_OUT_OF_MEMORY; } return CURLE_OK; } diff --git a/lib/multi_ev.c b/lib/multi_ev.c index 9e2b039edf..b1900cb14f 100644 --- a/lib/multi_ev.c +++ b/lib/multi_ev.c @@ -453,10 +453,8 @@ mev_add_new_conn_pollset(struct connectdata *conn) ps = calloc(1, sizeof(*ps)); if(!ps) return NULL; - if(Curl_conn_meta_set(conn, CURL_META_MEV_POLLSET, ps, mev_pollset_dtor)) { - free(ps); + if(Curl_conn_meta_set(conn, CURL_META_MEV_POLLSET, ps, mev_pollset_dtor)) return NULL; - } return ps; } @@ -468,10 +466,8 @@ mev_add_new_xfer_pollset(struct Curl_easy *data) ps = calloc(1, sizeof(*ps)); if(!ps) return NULL; - if(Curl_meta_set(data, CURL_META_MEV_POLLSET, ps, mev_pollset_dtor)) { - free(ps); + if(Curl_meta_set(data, CURL_META_MEV_POLLSET, ps, mev_pollset_dtor)) return NULL; - } return ps; } diff --git a/lib/url.c b/lib/url.c index e47ae60957..41c714ae53 100644 --- a/lib/url.c +++ b/lib/url.c @@ -3965,9 +3965,11 @@ CURLcode Curl_conn_meta_set(struct connectdata *conn, const char *key, if(!Curl_hash_add2(&conn->meta_hash, CURL_UNCONST(key), strlen(key) + 1, meta_data, meta_dtor)) { meta_dtor(CURL_UNCONST(key), strlen(key) + 1, meta_data); + return CURLE_OUT_OF_MEMORY; } return CURLE_OK; } + void Curl_conn_meta_remove(struct connectdata *conn, const char *key) { Curl_hash_delete(&conn->meta_hash, CURL_UNCONST(key), strlen(key) + 1);