]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
meta data handling for easy/conn fixes
authorStefan Eissing <stefan@eissing.org>
Tue, 29 Apr 2025 08:53:34 +0000 (10:53 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 29 Apr 2025 11:57:16 +0000 (13:57 +0200)
- return error when adding to hash fails
- do not free passed in data, as ownership is taken by call

Closes #17219

lib/doh.c
lib/easy.c
lib/multi_ev.c
lib/url.c

index 64fb54e33ac6336222ef73f3dde3fa81f0c6683c..672842ba8353a05541da9af3a1b14b07a423a777 100644 (file)
--- 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
index 7fc285f7b9d9a3a687fc4e3bb503b352afd469bf..af913bffa2c9cfbff71529c450d35a97e7c6f850 100644 (file)
@@ -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;
 }
index 9e2b039edfca1fcc288e46e2bf60ef95e554dacb..b1900cb14faca2741b25caa3bed29c689412f795 100644 (file)
@@ -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;
 }
 
index e47ae6095765688d273a23b68773b3fb0cc69bf4..41c714ae53e23cd275657661e6d2aa33a181da9a 100644 (file)
--- 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);