summaryrefslogtreecommitdiff
path: root/libc/netbsd/resolv/res_init.c
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2011-03-17 21:31:33 +0100
committerDavid 'Digit' Turner <digit@google.com>2011-03-18 18:08:08 +0100
commit4661fda2e5339c39ceb3aefd184eb8be3d0ca835 (patch)
tree99a502f7e823ad87026a93bbf2add5272ac843fd /libc/netbsd/resolv/res_init.c
parentec7e8cc9dddafc624cd28939c1a38ea336c89455 (diff)
libc: Fix leak in the DNS thread-specific state.
This patch fixes a leak that occurs when creating a new thread-specific DNS resolver state object. Essentially, each thread that calls gethostbyname() or getaddrinfo() at least once will leak a small memory block. Another leak happens anytime these functions are called after a change of the network settings. The leak is insignificant and hard to notice on typical programs. However, netd tends to create one new thread for each DNS request it processes, and quickly grows in size after a > 20 hours. The same problem is seen in other system processes that tend to create one thread per request too. The leak occured becasue res_ninit() was called twice when creating a new thread-specific DNS resolver state in _res_get_thread(). This function could not properly reset an existing thread and was leaking a memory block. The patch does two things: - First, it fixes res_ninit() to prevent any leakage when resetting the state of a given res_state instance. - Second, it modifies the _res_get_thread() implementation to make it more explicit, and avoid calling res_ninit() twice in a row on first-time creation. Fix for Bug 4089945, and Bug 4090857 Change-Id: Ie4831a8dbe82be8f07fce5ddd1d36bf95994f836
Diffstat (limited to 'libc/netbsd/resolv/res_init.c')
-rw-r--r--libc/netbsd/resolv/res_init.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/libc/netbsd/resolv/res_init.c b/libc/netbsd/resolv/res_init.c
index 2158f2062..ffd4054cd 100644
--- a/libc/netbsd/resolv/res_init.c
+++ b/libc/netbsd/resolv/res_init.c
@@ -225,6 +225,9 @@ __res_vinit(res_state statp, int preinit) {
char dnsProperty[PROP_VALUE_MAX];
#endif
+ if ((statp->options & RES_INIT) != 0U)
+ res_ndestroy(statp);
+
if (!preinit) {
statp->retrans = RES_TIMEOUT;
statp->retry = RES_DFLRETRY;
@@ -232,9 +235,6 @@ __res_vinit(res_state statp, int preinit) {
statp->id = res_randomid();
}
- if ((statp->options & RES_INIT) != 0U)
- res_ndestroy(statp);
-
memset(u, 0, sizeof(u));
#ifdef USELOOPBACK
u[nserv].sin.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);