diff options
author | Daniel Stenberg <daniel@haxx.se> | 2022-08-15 16:49:44 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2022-08-16 08:54:33 +0200 |
commit | 14d9d79c871e270dfee726fef9a4dd098862c91d (patch) | |
tree | d05a86236f9a9a949ff524ff6b47c392c22e2f7d /lib/asyn-ares.c | |
parent | 37dbbbb6c14bcbd696441e15b41cc3d1c74c486c (diff) | |
download | curl-14d9d79c871e270dfee726fef9a4dd098862c91d.tar.gz |
asyn-ares: make a single alloc out of hostname + async data
This saves one alloc per name resolve and simplifies the exit path.
Closes #9310
Diffstat (limited to 'lib/asyn-ares.c')
-rw-r--r-- | lib/asyn-ares.c | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/lib/asyn-ares.c b/lib/asyn-ares.c index 8b620a1d6..fb933b5ed 100644 --- a/lib/asyn-ares.c +++ b/lib/asyn-ares.c @@ -115,6 +115,7 @@ struct thread_data { #ifndef HAVE_CARES_GETADDRINFO struct curltime happy_eyeballs_dns_time; /* when this timer started, or 0 */ #endif + char hostname[1]; }; /* How long we are willing to wait for additional parallel responses after @@ -252,8 +253,6 @@ void Curl_resolver_kill(struct Curl_easy *data) */ static void destroy_async_data(struct Curl_async *async) { - free(async->hostname); - if(async->tdata) { struct thread_data *res = async->tdata; if(res) { @@ -265,8 +264,6 @@ static void destroy_async_data(struct Curl_async *async) } async->tdata = NULL; } - - async->hostname = NULL; } /* @@ -758,25 +755,18 @@ struct Curl_addrinfo *Curl_resolver_getaddrinfo(struct Curl_easy *data, int port, int *waitp) { - char *bufp; - + struct thread_data *res = NULL; + size_t namelen = strlen(hostname); *waitp = 0; /* default to synchronous response */ - bufp = strdup(hostname); - if(bufp) { - struct thread_data *res = NULL; - free(data->state.async.hostname); - data->state.async.hostname = bufp; + res = calloc(sizeof(struct thread_data) + namelen, 1); + if(res) { + strcpy(res->hostname, hostname); + data->state.async.hostname = res->hostname; data->state.async.port = port; data->state.async.done = FALSE; /* not done */ data->state.async.status = 0; /* clear */ data->state.async.dns = NULL; /* clear */ - res = calloc(sizeof(struct thread_data), 1); - if(!res) { - free(data->state.async.hostname); - data->state.async.hostname = NULL; - return NULL; - } data->state.async.tdata = res; /* initial status - failed */ |