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

@ -1253,7 +1253,8 @@ CURLcode Curl_doh_is_resolved(struct Curl_easy *data,
goto error;
/* we got a response, create a dns entry. */
dns = Curl_dnscache_mk_entry(data, ai, dohp->host, 0, dohp->port, FALSE);
dns = Curl_dnscache_mk_entry(data, &ai, dohp->host, 0,
dohp->port, FALSE);
if(dns) {
/* Now add and HTTPSRR information if we have */
#ifdef USE_HTTPSRR
@ -1278,8 +1279,6 @@ CURLcode Curl_doh_is_resolved(struct Curl_easy *data,
result = Curl_dnscache_add(data, dns);
*dnsp = data->state.async.dns;
}
else
Curl_freeaddrinfo(ai);
} /* address processing done */
/* All done */