* 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>.
This commit is contained in:
Ulrich Drepper 1999-05-02 21:03:32 +00:00
parent 48afc878d8
commit 238ae1eb66
2 changed files with 22 additions and 12 deletions

View File

@ -1,5 +1,11 @@
1999-05-02 Ulrich Drepper <drepper@cygnus.com> 1999-05-02 Ulrich Drepper <drepper@cygnus.com>
* 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>.
* sysdeps/unix/sysv/linux/sys/procfs.h: Remove greg_t, gregset_t, * sysdeps/unix/sysv/linux/sys/procfs.h: Remove greg_t, gregset_t,
and fpregset_t definition. They are defined in ucontext.h. and fpregset_t definition. They are defined in ucontext.h.

View File

@ -190,7 +190,7 @@ gaih_local (const char *name, const struct gaih_service *service,
static int static int
gaih_inet_serv (const char *servicename, struct gaih_typeproto *tp, gaih_inet_serv (const char *servicename, struct gaih_typeproto *tp,
struct gaih_servtuple **st) struct gaih_servtuple *st)
{ {
struct servent *s; struct servent *s;
size_t tmpbuflen = 1024; size_t tmpbuflen = 1024;
@ -216,14 +216,10 @@ gaih_inet_serv (const char *servicename, struct gaih_typeproto *tp,
} }
while (r); while (r);
*st = malloc (sizeof (struct gaih_servtuple)); st->next = NULL;
if (*st == NULL) st->socktype = tp->socktype;
return -EAI_MEMORY; 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; return 0;
} }
@ -297,7 +293,10 @@ gaih_inet (const char *name, const struct gaih_service *service,
{ {
if (tp->name != NULL) 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; return rc;
} }
else else
@ -305,13 +304,18 @@ gaih_inet (const char *name, const struct gaih_service *service,
struct gaih_servtuple **pst = &st; struct gaih_servtuple **pst = &st;
for (tp++; tp->name; tp++) 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) if (rc & GAIH_OKIFUNSPEC)
continue; continue;
return rc; return rc;
} }
pst = &((*pst)->next);
*pst = newp;
pst = &(newp->next);
} }
if (st == &nullserv) if (st == &nullserv)
return (GAIH_OKIFUNSPEC | -EAI_SERVICE); return (GAIH_OKIFUNSPEC | -EAI_SERVICE);