ngx_resolver.c leaks memory?

Matthew Dempsky matthew at
Wed Sep 16 09:28:37 MSD 2009

I'm still familiarizing myself with nginx's architecture, but it looks
like ngx_resolver.c leaks memory in a few places.  Before I spend any
time tracking more down, I thought I'd point out one apparent leak so
someone can perhaps correct me before I waste my time.

In ngx_resolver_process_a(), ngx_resolver_copy() is used to
dynamically allocate memory into  This memory is only
passed to a few logging functions and to ngx_resolver_lookup_name().
(The name variable is also reused in the CNAME handling path, but it's
first overwritten by another call to ngx_resolver_copy().)

There does not appear to be any code responsible for ensuring that is freed.  Is there any deeper architecture preventing this
memory from being leaked that I've missed?

Included below is a patch that I believe fixes this particular memory
leak.  If someone can confirm that this is indeed correct, I'll
continue investigating the other apparent leaks.


--- src/core/ngx_resolver.c.orig	2009-09-15 22:12:31.000000000 -0700
+++ src/core/ngx_resolver.c	2009-09-15 22:24:06.000000000 -0700
@@ -1149,6 +1149,8 @@ ngx_resolver_process_a(ngx_resolver_t *r
         goto failed;

+    ngx_resolver_free(r,;
     if (code == 0 && nan == 0) {
         code = 3; /* NXDOMAIN */
@@ -1400,6 +1402,8 @@ failed:

     /* unlock name mutex */

+    ngx_resolver_free(r,;

More information about the nginx mailing list