diff options
author | Yu Jiung <jiung.yu@samsung.com> | 2016-11-09 11:18:45 +0900 |
---|---|---|
committer | Yu Jiung <jiung.yu@samsung.com> | 2016-11-09 11:18:55 +0900 |
commit | eb886f120599b2a184db20b527db6dfdfcb7852e (patch) | |
tree | b49d8075742c4a27b237fa183cb68670e421d398 /ares_gethostbyname.c | |
parent | b6627e2c19506bd30328969ea8aab73fa0945f36 (diff) | |
download | c-ares-eb886f120599b2a184db20b527db6dfdfcb7852e.tar.gz c-ares-eb886f120599b2a184db20b527db6dfdfcb7852e.tar.bz2 c-ares-eb886f120599b2a184db20b527db6dfdfcb7852e.zip |
Imported Upstream version 1.11.0upstream/1.11.0
Change-Id: I238c24b75a10aa902d9bc4076ed68b76b5e2a750
Diffstat (limited to 'ares_gethostbyname.c')
-rw-r--r-- | ares_gethostbyname.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/ares_gethostbyname.c b/ares_gethostbyname.c index 2b27b2e..caab6ae 100644 --- a/ares_gethostbyname.c +++ b/ares_gethostbyname.c @@ -99,18 +99,18 @@ void ares_gethostbyname(ares_channel channel, const char *name, int family, return; /* Allocate and fill in the host query structure. */ - hquery = malloc(sizeof(struct host_query)); + hquery = ares_malloc(sizeof(struct host_query)); if (!hquery) { callback(arg, ARES_ENOMEM, 0, NULL); return; } hquery->channel = channel; - hquery->name = strdup(name); + hquery->name = ares_strdup(name); hquery->want_family = family; hquery->sent_family = -1; /* nothing is sent yet */ if (!hquery->name) { - free(hquery); + ares_free(hquery); callback(arg, ARES_ENOMEM, 0, NULL); return; } @@ -188,11 +188,14 @@ static void host_callback(void *arg, int status, int timeouts, else if (hquery->sent_family == AF_INET6) { status = ares_parse_aaaa_reply(abuf, alen, &host, NULL, NULL); - if ((status == ARES_ENODATA || status == ARES_EBADRESP) && - hquery->want_family == AF_UNSPEC) { + if ((status == ARES_ENODATA || status == ARES_EBADRESP || + (status == ARES_SUCCESS && host && host->h_addr_list[0] == NULL)) && + hquery->want_family == AF_UNSPEC) { /* The query returned something but either there were no AAAA records (e.g. just CNAME) or the response was malformed. Try looking up A instead. */ + if (host) + ares_free_hostent(host); hquery->sent_family = AF_INET; ares_search(hquery->channel, hquery->name, C_IN, T_A, host_callback, hquery); @@ -224,8 +227,8 @@ static void end_hquery(struct host_query *hquery, int status, hquery->callback(hquery->arg, status, hquery->timeouts, host); if (host) ares_free_hostent(host); - free(hquery->name); - free(hquery); + ares_free(hquery->name); + ares_free(hquery); } /* If the name looks like an IP address, fake up a host entry, end the @@ -284,7 +287,7 @@ static int fake_hostent(const char *name, int family, addrs[0] = (char *)&in6; } /* Duplicate the name, to avoid a constness violation. */ - hostent.h_name = strdup(name); + hostent.h_name = ares_strdup(name); if (!hostent.h_name) { callback(arg, ARES_ENOMEM, 0, NULL); @@ -298,7 +301,7 @@ static int fake_hostent(const char *name, int family, hostent.h_addr_list = addrs; callback(arg, ARES_SUCCESS, 0, &hostent); - free((char *)(hostent.h_name)); + ares_free((char *)(hostent.h_name)); return 1; } |