ares: handle channel being destroyed early

We are destroying the ares channel already when we shutdown
resolving. Querying the pollset afterwards is still happening,
especially in event based processing and needs to work in the
absence of a channel.

Fixes #18317
Reported-by: Natris on github
Closes #18318
This commit is contained in:
Stefan Eissing 2025-08-19 15:46:34 +02:00 committed by Daniel Stenberg
parent 52775a7fb4
commit faa2db202b
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2
2 changed files with 9 additions and 2 deletions

View File

@ -280,8 +280,9 @@ void Curl_async_ares_destroy(struct Curl_easy *data)
CURLcode Curl_async_pollset(struct Curl_easy *data, struct easy_pollset *ps)
{
struct async_ares_ctx *ares = &data->state.async.ares;
DEBUGASSERT(ares->channel);
return Curl_ares_pollset(data, ares->channel, ps);
if(ares->channel)
return Curl_ares_pollset(data, ares->channel, ps);
return CURLE_OK;
}
/*

View File

@ -91,6 +91,10 @@ CURLcode Curl_ares_pollset(struct Curl_easy *data,
timediff_t milli;
CURLcode result = CURLE_OK;
DEBUGASSERT(channel);
if(!channel)
return CURLE_FAILED_INIT;
bitmap = ares_getsock(channel, (ares_socket_t *)sockets,
CURL_ARRAYSIZE(sockets));
for(i = 0; i < CURL_ARRAYSIZE(sockets); ++i) {
@ -107,6 +111,8 @@ CURLcode Curl_ares_pollset(struct Curl_easy *data,
}
timeout = ares_timeout(channel, &maxtime, &timebuf);
if(!timeout)
timeout = &maxtime;
milli = curlx_tvtoms(timeout);
Curl_expire(data, milli, EXPIRE_ASYNC_NAME);
return result;