getaddrinfo: Unconditionally use malloc for address list

getaddrinfo has to call malloc eventually anyway, so the complexity
of avoiding malloc calls is not worth potential savings.
This commit is contained in:
Florian Weimer 2017-05-11 10:01:49 +02:00
parent faa9066c4b
commit 46ce8881ad
2 changed files with 10 additions and 24 deletions

View File

@ -1,3 +1,8 @@
2017-05-11 Florian Weimer <fweimer@redhat.com>
* sysdeps/posix/getaddrinfo.c (gethosts): Remove malloc_addrmem.
(gaih_inet): Likewise.
2017-05-10 Andreas Schwab <schwab@suse.de> 2017-05-10 Andreas Schwab <schwab@suse.de>
* nptl/tst-fork1.c: Include <support/test-driver.c>. * nptl/tst-fork1.c: Include <support/test-driver.c>.

View File

@ -278,9 +278,6 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req,
} \ } \
else if (h != NULL) \ else if (h != NULL) \
{ \ { \
/* Make sure that addrmem can be freed. */ \
if (!malloc_addrmem) \
addrmem = NULL; \
if (!convert_hostent_to_gaih_addrtuple (req, _family,h, &addrmem)) \ if (!convert_hostent_to_gaih_addrtuple (req, _family,h, &addrmem)) \
{ \ { \
_res.options |= old_res_options & DEPRECATED_RES_USE_INET6; \ _res.options |= old_res_options & DEPRECATED_RES_USE_INET6; \
@ -288,8 +285,6 @@ convert_hostent_to_gaih_addrtuple (const struct addrinfo *req,
goto free_and_return; \ goto free_and_return; \
} \ } \
*pat = addrmem; \ *pat = addrmem; \
/* The conversion uses malloc unconditionally. */ \
malloc_addrmem = true; \
\ \
if (localcanon != NULL && canon == NULL) \ if (localcanon != NULL && canon == NULL) \
canon = strdupa (localcanon); \ canon = strdupa (localcanon); \
@ -447,7 +442,6 @@ gaih_inet (const char *name, const struct gaih_service *service,
} }
bool malloc_name = false; bool malloc_name = false;
bool malloc_addrmem = false;
struct gaih_addrtuple *addrmem = NULL; struct gaih_addrtuple *addrmem = NULL;
bool malloc_canonbuf = false; bool malloc_canonbuf = false;
char *canonbuf = NULL; char *canonbuf = NULL;
@ -633,8 +627,6 @@ gaih_inet (const char *name, const struct gaih_service *service,
goto free_and_return; goto free_and_return;
} }
*pat = addrmem; *pat = addrmem;
/* The conversion uses malloc unconditionally. */
malloc_addrmem = true;
} }
} }
else else
@ -675,21 +667,11 @@ gaih_inet (const char *name, const struct gaih_service *service,
bool added_canon = (req->ai_flags & AI_CANONNAME) == 0; bool added_canon = (req->ai_flags & AI_CANONNAME) == 0;
char *addrs = air->addrs; char *addrs = air->addrs;
if (__libc_use_alloca (alloca_used addrmem = calloc (air->naddrs, sizeof (*addrmem));
+ air->naddrs * sizeof (struct gaih_addrtuple))) if (addrmem == NULL)
addrmem = alloca_account (air->naddrs
* sizeof (struct gaih_addrtuple),
alloca_used);
else
{ {
addrmem = malloc (air->naddrs result = -EAI_MEMORY;
* sizeof (struct gaih_addrtuple)); goto free_and_return;
if (addrmem == NULL)
{
result = -EAI_MEMORY;
goto free_and_return;
}
malloc_addrmem = true;
} }
struct gaih_addrtuple *addrfree = addrmem; struct gaih_addrtuple *addrfree = addrmem;
@ -1232,8 +1214,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
free_and_return: free_and_return:
if (malloc_name) if (malloc_name)
free ((char *) name); free ((char *) name);
if (malloc_addrmem) free (addrmem);
free (addrmem);
if (malloc_canonbuf) if (malloc_canonbuf)
free (canonbuf); free (canonbuf);