diff options
Diffstat (limited to 'sysdeps/posix/getaddrinfo.c')
-rw-r--r-- | sysdeps/posix/getaddrinfo.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c index fc0928676d..224381c8db 100644 --- a/sysdeps/posix/getaddrinfo.c +++ b/sysdeps/posix/getaddrinfo.c @@ -1042,12 +1042,16 @@ gaih_inet (const char *name, const struct gaih_service *service, else socklen = sizeof (struct sockaddr_in); + struct addrinfo *pai_1st = pai; for (st2 = st; st2 != NULL; st2 = st2->next) { struct addrinfo *ai; ai = *pai = malloc (sizeof (struct addrinfo) + socklen); if (ai == NULL) - return -EAI_MEMORY; + { + free ((char *) canon); + return -EAI_MEMORY; + } ai->ai_flags = req->ai_flags; ai->ai_family = family; @@ -1065,6 +1069,10 @@ gaih_inet (const char *name, const struct gaih_service *service, #endif /* _HAVE_SA_LEN */ ai->ai_addr->sa_family = family; + /* In case of an allocation error the list must be NULL + terminated. */ + ai->ai_next = NULL; + if (family == AF_INET6) { struct sockaddr_in6 *sin6p = @@ -1088,7 +1096,6 @@ gaih_inet (const char *name, const struct gaih_service *service, pai = &(ai->ai_next); } - *pai = NULL; ++*naddrs; |