From: x2018 Date: Fri, 31 Oct 2025 19:43:26 +0000 (+0800) Subject: doh: cleanup resources on error paths X-Git-Tag: curl-8_17_0~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f6bbc2b3be510a3c7e469cd697132ca1046290b5;p=thirdparty%2Fcurl.git doh: cleanup resources on error paths Closes #19310 --- diff --git a/lib/doh.c b/lib/doh.c index 8cdecf4657..ec97bd7333 100644 --- a/lib/doh.c +++ b/lib/doh.c @@ -1219,8 +1219,9 @@ UNITTEST void doh_print_httpsrr(struct Curl_easy *data, CURLcode Curl_doh_is_resolved(struct Curl_easy *data, struct Curl_dns_entry **dnsp) { - CURLcode result; + CURLcode result = CURLE_OK; struct doh_probes *dohp = data->state.async.doh; + struct dohentry de; *dnsp = NULL; /* defaults to no response */ if(!dohp) return CURLE_OUT_OF_MEMORY; @@ -1233,7 +1234,6 @@ CURLcode Curl_doh_is_resolved(struct Curl_easy *data, } else if(!dohp->pending) { DOHcode rc[DOH_SLOT_COUNT]; - struct dohentry de; int slot; /* Clear any result the might still be there */ @@ -1265,17 +1265,14 @@ CURLcode Curl_doh_is_resolved(struct Curl_easy *data, struct Curl_dns_entry *dns; struct Curl_addrinfo *ai; - if(Curl_trc_ft_is_verbose(data, &Curl_trc_feat_dns)) { CURL_TRC_DNS(data, "hostname: %s", dohp->host); doh_show(data, &de); } result = doh2ai(&de, dohp->host, dohp->port, &ai); - if(result) { - de_cleanup(&de); - return result; - } + if(result) + goto error; /* we got a response, create a dns entry. */ dns = Curl_dnscache_mk_entry(data, ai, dohp->host, 0, dohp->port, FALSE); @@ -1288,7 +1285,8 @@ CURLcode Curl_doh_is_resolved(struct Curl_easy *data, de.https_rrs->len, &hrr); if(result) { infof(data, "Failed to decode HTTPS RR"); - return result; + Curl_resolv_unlink(data, &dns); + goto error; } infof(data, "Some HTTPS RR to process"); # ifdef DEBUGBUILD @@ -1306,14 +1304,15 @@ CURLcode Curl_doh_is_resolved(struct Curl_easy *data, /* All done */ data->state.async.done = TRUE; - de_cleanup(&de); - Curl_doh_cleanup(data); - return result; - } /* !dohp->pending */ + else + /* wait for pending DoH transactions to complete */ + return CURLE_OK; - /* else wait for pending DoH transactions to complete */ - return CURLE_OK; +error: + de_cleanup(&de); + Curl_doh_cleanup(data); + return result; } void Curl_doh_close(struct Curl_easy *data)