platform_bionic/libc/netbsd
David 'Digit' Turner b6cd6816d2 libc: Fix leak in the DNS thread-specific state.
NOTE: This is a back-port from the internal HC branch.

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: Icde1d4d1dfb9383efdbf38d0658ba915be77942e
2011-05-18 13:48:20 +02:00
..
inet auto import from //depot/cupcake/@135843 2009-03-03 19:28:35 -08:00
isc Remove compiler warnings when building Bionic. 2010-06-22 17:51:41 -07:00
nameser Remove compiler warnings when building Bionic. 2010-06-22 17:51:41 -07:00
net Tracking change to dns proxy protocol 2011-04-29 16:43:16 -07:00
resolv libc: Fix leak in the DNS thread-specific state. 2011-05-18 13:48:20 +02:00
gethnamaddr.c gethnamaddr: make helper functions static 2010-09-27 23:40:55 +08:00