diff options
Diffstat (limited to 'ares_search.c')
-rw-r--r-- | ares_search.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/ares_search.c b/ares_search.c index 45ba0a0..68e8525 100644 --- a/ares_search.c +++ b/ares_search.c @@ -44,7 +44,7 @@ static void search_callback(void *arg, int status, int timeouts, static void end_squery(struct search_query *squery, int status, unsigned char *abuf, int alen); static int cat_domain(const char *name, const char *domain, char **s); -static int single_domain(ares_channel channel, const char *name, char **s); +STATIC_TESTABLE int single_domain(ares_channel channel, const char *name, char **s); void ares_search(ares_channel channel, const char *name, int dnsclass, int type, ares_callback callback, void *arg) @@ -66,24 +66,24 @@ void ares_search(ares_channel channel, const char *name, int dnsclass, if (s) { ares_query(channel, s, dnsclass, type, callback, arg); - free(s); + ares_free(s); return; } /* Allocate a search_query structure to hold the state necessary for * doing multiple lookups. */ - squery = malloc(sizeof(struct search_query)); + squery = ares_malloc(sizeof(struct search_query)); if (!squery) { callback(arg, ARES_ENOMEM, 0, NULL, 0); return; } squery->channel = channel; - squery->name = strdup(name); + squery->name = ares_strdup(name); if (!squery->name) { - free(squery); + ares_free(squery); callback(arg, ARES_ENOMEM, 0, NULL, 0); return; } @@ -123,13 +123,13 @@ void ares_search(ares_channel channel, const char *name, int dnsclass, if (status == ARES_SUCCESS) { ares_query(channel, s, dnsclass, type, search_callback, squery); - free(s); + ares_free(s); } else { /* failed, free the malloc()ed memory */ - free(squery->name); - free(squery); + ares_free(squery->name); + ares_free(squery); callback(arg, status, 0, NULL, 0); } } @@ -177,7 +177,7 @@ static void search_callback(void *arg, int status, int timeouts, squery->next_domain++; ares_query(channel, s, squery->dnsclass, squery->type, search_callback, squery); - free(s); + ares_free(s); } } else if (squery->status_as_is == -1) @@ -201,8 +201,8 @@ static void end_squery(struct search_query *squery, int status, unsigned char *abuf, int alen) { squery->callback(squery->arg, status, squery->timeouts, abuf, alen); - free(squery->name); - free(squery); + ares_free(squery->name); + ares_free(squery); } /* Concatenate two domains. */ @@ -211,7 +211,7 @@ static int cat_domain(const char *name, const char *domain, char **s) size_t nlen = strlen(name); size_t dlen = strlen(domain); - *s = malloc(nlen + 1 + dlen + 1); + *s = ares_malloc(nlen + 1 + dlen + 1); if (!*s) return ARES_ENOMEM; memcpy(*s, name, nlen); @@ -225,7 +225,7 @@ static int cat_domain(const char *name, const char *domain, char **s) * the string we should query, in an allocated buffer. If not, set *s * to NULL. */ -static int single_domain(ares_channel channel, const char *name, char **s) +STATIC_TESTABLE int single_domain(ares_channel channel, const char *name, char **s) { size_t len = strlen(name); const char *hostaliases; @@ -239,9 +239,9 @@ static int single_domain(ares_channel channel, const char *name, char **s) /* If the name contains a trailing dot, then the single query is the name * sans the trailing dot. */ - if (name[len - 1] == '.') + if ((len > 0) && (name[len - 1] == '.')) { - *s = strdup(name); + *s = ares_strdup(name); return (*s) ? ARES_SUCCESS : ARES_ENOMEM; } @@ -251,7 +251,7 @@ static int single_domain(ares_channel channel, const char *name, char **s) hostaliases = getenv("HOSTALIASES"); if (hostaliases) { - fp = fopen(hostaliases, "re"); + fp = fopen(hostaliases, "r"); if (fp) { while ((status = ares__read_line(fp, &line, &linesize)) @@ -268,18 +268,18 @@ static int single_domain(ares_channel channel, const char *name, char **s) q = p + 1; while (*q && !ISSPACE(*q)) q++; - *s = malloc(q - p + 1); + *s = ares_malloc(q - p + 1); if (*s) { memcpy(*s, p, q - p); (*s)[q - p] = 0; } - free(line); + ares_free(line); fclose(fp); return (*s) ? ARES_SUCCESS : ARES_ENOMEM; } } - free(line); + ares_free(line); fclose(fp); if (status != ARES_SUCCESS && status != ARES_EOF) return status; @@ -307,7 +307,7 @@ static int single_domain(ares_channel channel, const char *name, char **s) if (channel->flags & ARES_FLAG_NOSEARCH || channel->ndomains == 0) { /* No domain search to do; just try the name as-is. */ - *s = strdup(name); + *s = ares_strdup(name); return (*s) ? ARES_SUCCESS : ARES_ENOMEM; } |