[Home]

Summary:ASTERISK-09819: Large memory leak in dns.c:ast_search_dns()
Reporter:Steve Woodford (scw)Labels:
Date Opened:2007-07-06 01:49:21Date Closed:2007-07-10 13:24:18
Priority:MinorRegression?No
Status:Closed/CompleteComponents:Addons/General
Versions:Frequency of
Occurrence
Related
Issues:
Environment:Attachments:( 0) ndestroy-1.2.diff
( 1) ndestroy-1.4.diff
Description:On NetBSD (and almost certainly others), each call to ast_search_dns() will leak more than 800 bytes of memory. This is particularly noticeable with several "register" entries in sip.conf and a short registration interval, where the asterisk process can consume 5-6MB of leaked memory in a 24 hour period.

When HAS_RES_NINIT is defined, ast_search_dns() invokes res_ninit() to initialise a local dnsstate variable. This variable is then used during nameserver lookups in res_search(). On completion, ast_search_dns() calls res_nclose() in an attempt to clean up.

Unfortunately, with NetBSD's BIND-based resolver (and probably any other OS using the same BIND code, like FreeBSD), res_nclose() doesn't free all state. Instead, ast_search_dns() must invoke res_ndestroy() to ensure all state is freed. Note that res_ndestroy() does an implicit res_nclose(), so simply replacing the call to res_nclose() with res_ndestroy() will do the right thing.





****** ADDITIONAL INFORMATION ******

I've marked this as a bug in 1.4.6, but it also affects 1.2.20.
Comments:By: Jason Parker (jparker) 2007-07-06 10:05:24

Try these patches..  Do they seem right?

By: Steve Woodford (scw) 2007-07-07 13:06:18

The patches look fine to me.

Cheers, Steve

By: Digium Subversion (svnbot) 2007-07-10 13:24:18

Repository: asterisk
Revision: 74375

------------------------------------------------------------------------
r74375 | qwell | 2007-07-10 13:24:17 -0500 (Tue, 10 Jul 2007) | 22 lines

Merged revisions 74374 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.4

(closes issue ASTERISK-9819)
................
r74374 | qwell | 2007-07-10 13:39:30 -0500 (Tue, 10 Jul 2007) | 13 lines

Merged revisions 74373 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r74373 | qwell | 2007-07-10 13:37:23 -0500 (Tue, 10 Jul 2007) | 5 lines

Use res_ndestroy on systems that have it.  Otherwise, use res_nclose.
This prevents a memleak on NetBSD - and possibly others.

Issue 10133, patch by me, reported and tested by scw

........

................

------------------------------------------------------------------------