]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
c-hyper: fix a memory leak in `Curl_http`.
authorNicholas Nethercote <n.nethercote@gmail.com>
Fri, 25 Aug 2023 05:01:53 +0000 (15:01 +1000)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 25 Aug 2023 13:27:11 +0000 (15:27 +0200)
A request created with `hyper_request_new` must be consumed by either
`hyper_clientconn_send` or `hyper_request_free`.

This is not terrifically clear from the hyper docs --
`hyper_request_free` is documented only with "Free an HTTP request if
not going to send it on a client" -- but a perusal of the hyper code
confirms it.

This commit adds a `hyper_request_free` to the `error:` path in
`Curl_http` so that the request is consumed when an error occurs after
the request is created but before it is sent.

Fixes the first memory leak reported by Valgrind in #10803.

Closes #11729

lib/c-hyper.c

index 18d9206ca7966e4fc2fd6f7a6821e1a2aaf50ae9..ebb885669b7a270cfae1612ac0c4789a5be2b0af 100644 (file)
@@ -1208,6 +1208,7 @@ CURLcode Curl_http(struct Curl_easy *data, bool *done)
     result = CURLE_OUT_OF_MEMORY;
     goto error;
   }
+  req = NULL;
 
   if(HYPERE_OK != hyper_executor_push(h->exec, sendtask)) {
     failf(data, "Couldn't hyper_executor_push the send");
@@ -1244,6 +1245,9 @@ error:
   if(handshake)
     hyper_task_free(handshake);
 
+  if(req)
+    hyper_request_free(req);
+
   return result;
 }