hostip.c: fix leak of addrinfo

When creating a dns entry, the addrinfo is passed into the entry on
success and needed deallocation by the caller on failure.

Change the signature to have Curl_dnscache_mk_entry() *always* take
ownership of the addrinfo, even on failure. Change parameter to address
of pointer so that call always clears it.

This makes the handling of failures to Curl_dnscache_mk_entry() simpler.

Fixes #20465
Closes #20468
This commit is contained in:
Stefan Eissing 2026-01-29 11:59:05 +01:00 committed by Daniel Stenberg
parent a84b041281
commit ffdbc04c7b
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
5 changed files with 24 additions and 27 deletions

View file

@ -151,13 +151,14 @@ void Curl_printable_address(const struct Curl_addrinfo *ip,
* The entry is created with a reference count of 1.
* Use `Curl_resolv_unlink()` to release your hold on it.
*
* The call takes ownership of `addr`and makes a copy of `hostname`.
* The call takes ownership of `addr`, even in case of failure, and always
* clears `*paddr`. It makes a copy of `hostname`.
*
* Returns entry or NULL on OOM.
*/
struct Curl_dns_entry *
Curl_dnscache_mk_entry(struct Curl_easy *data,
struct Curl_addrinfo *addr,
struct Curl_addrinfo **paddr,
const char *hostname,
size_t hostlen, /* length or zero */
int port,