[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
library/1907: small memory leak in res_init (gethostbyname)
- To: gnats@openbsd.org
- Subject: library/1907: small memory leak in res_init (gethostbyname)
- From: andrew@etunnels.com
- Date: Fri, 29 Jun 2001 16:58:02 -0700 (PDT)
- Resent-Date: Fri, 29 Jun 2001 18:10:03 -0600 (MDT)
- Resent-From: gnats@cvs.openbsd.org (GNATS Management)
- Resent-Message-Id: <200106300010.f5U0A3826195@cvs.openbsd.org>
- Resent-Reply-To: gnats@cvs.openbsd.org, andrew@etunnels.com
- Resent-To: bugs@cvs.openbsd.org
>Number: 1907
>Category: library
>Synopsis: small memory leak in res_init (gethostbyname)
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: bugs
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Jun 29 18:10:01 MDT 2001
>Last-Modified:
>Originator: Andrew Campbell
>Organization:
net
>Release: 2.8, 2.9
>Environment:
System : OpenBSD 2.8
Architecture: OpenBSD.i386
Machine : i386
>Description:
In src/lib/libc/net/res_init.c, a call is made to
getaddrinfo(), with no corresponding call to freeaddrinfo().
This results in a one-time leak of 48 bytes (wahoo!).
>How-To-Repeat:
<code/input/activities to reproduce the problem (multiple
lines)>
>Fix:
<how to correct or work around the problem, if known (multiple
lines)>
Here's a patch to the 2.8 version of res_init.c that fixes the
leak:
> cvs diff res_init.c
Index: res_init.c
===================================================================
RCS file: /cvs/src/lib/libc/net/res_init.c,v
retrieving revision 1.19
diff -u -r1.19 res_init.c
--- res_init.c 2000/06/22 07:31:18 1.19
+++ res_init.c 2001/06/29 23:51:03
@@ -355,6 +355,7 @@
char *q;
struct addrinfo hints, *res;
char pbuf[NI_MAXSERV];
+ int error;
#else
struct in_addr a;
#endif /* INET6 */
@@ -375,7 +376,7 @@
hints.ai_flags = AI_NUMERICHOST;
hints.ai_socktype = SOCK_DGRAM;
snprintf(pbuf, sizeof(pbuf), "%d",
NAMESERVER_PORT);
- if (getaddrinfo(cp, pbuf, &hints, &res) == 0 &&
+ if ((error = getaddrinfo(cp, pbuf, &hints, &res))
== 0 &&
res->ai_next == NULL) {
if (res->ai_addrlen <=
sizeof(_res_ext.nsaddr_list[nserv])) {
memcpy(&_res_ext.nsaddr_list[nserv],
res->ai_addr,
@@ -393,6 +394,8 @@
}
nserv++;
}
+ if (!error)
+ freeaddrinfo(res);
#else /* INET6 */
if ((*cp != '\0') && (*cp != '\n') &&
inet_aton(cp, &a)) {
_res.nsaddr_list[nserv].sin_addr = a;
>Audit-Trail:
>Unformatted: