aboutsummaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>1999-05-02 21:03:32 +0000
committerUlrich Drepper <drepper@redhat.com>1999-05-02 21:03:32 +0000
commit238ae1eb669cd42b99471653c32d18a1c90cc787 (patch)
tree2be68b9df5ed8f9616eaed6aef190b33fb58ba8f /sysdeps
parent48afc878d8da73bd180c47a77167bb55712d91cc (diff)
downloadglibc-238ae1eb669cd42b99471653c32d18a1c90cc787.tar
glibc-238ae1eb669cd42b99471653c32d18a1c90cc787.tar.gz
glibc-238ae1eb669cd42b99471653c32d18a1c90cc787.tar.bz2
glibc-238ae1eb669cd42b99471653c32d18a1c90cc787.zip
Update.
* sysdeps/posix/getaddrinfo.c (gaih_inet_serv): Change fourth parameter to struct gaih_servtuple *. Adapt appropriately. (gaih_inet): Use alloca to allocate room for gaih_inet_serv calls. This fixes a memory leak. Reported by Mikolaj J. Habryn <dichro-glibcbug@rcpt.to>.
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/posix/getaddrinfo.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/sysdeps/posix/getaddrinfo.c b/sysdeps/posix/getaddrinfo.c
index bee95acabc..f43aa03d1f 100644
--- a/sysdeps/posix/getaddrinfo.c
+++ b/sysdeps/posix/getaddrinfo.c
@@ -190,7 +190,7 @@ gaih_local (const char *name, const struct gaih_service *service,
static int
gaih_inet_serv (const char *servicename, struct gaih_typeproto *tp,
- struct gaih_servtuple **st)
+ struct gaih_servtuple *st)
{
struct servent *s;
size_t tmpbuflen = 1024;
@@ -216,14 +216,10 @@ gaih_inet_serv (const char *servicename, struct gaih_typeproto *tp,
}
while (r);
- *st = malloc (sizeof (struct gaih_servtuple));
- if (*st == NULL)
- return -EAI_MEMORY;
-
- (*st)->next = NULL;
- (*st)->socktype = tp->socktype;
- (*st)->protocol = tp->protocol;
- (*st)->port = s->s_port;
+ st->next = NULL;
+ st->socktype = tp->socktype;
+ st->protocol = tp->protocol;
+ st->port = s->s_port;
return 0;
}
@@ -297,7 +293,10 @@ gaih_inet (const char *name, const struct gaih_service *service,
{
if (tp->name != NULL)
{
- if ((rc = gaih_inet_serv (service->name, tp, &st)))
+ st = (struct gaih_servtuple *)
+ __alloca (sizeof (struct gaih_servtuple));
+
+ if ((rc = gaih_inet_serv (service->name, tp, st)))
return rc;
}
else
@@ -305,13 +304,18 @@ gaih_inet (const char *name, const struct gaih_service *service,
struct gaih_servtuple **pst = &st;
for (tp++; tp->name; tp++)
{
- if ((rc = gaih_inet_serv (service->name, tp, pst)))
+ struct gaih_servtuple *newp = (struct gaih_servtuple *)
+ __alloca (sizeof (struct gaih_servtuple));
+
+ if ((rc = gaih_inet_serv (service->name, tp, newp)))
{
if (rc & GAIH_OKIFUNSPEC)
continue;
return rc;
}
- pst = &((*pst)->next);
+
+ *pst = newp;
+ pst = &(newp->next);
}
if (st == &nullserv)
return (GAIH_OKIFUNSPEC | -EAI_SERVICE);