ngx_resolver.c leaks memory?

Maxim Dounin mdounin at mdounin.ru
Wed Sep 16 14:35:09 MSD 2009


Hello!

On Tue, Sep 15, 2009 at 10:28:37PM -0700, Matthew Dempsky wrote:

> 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 name.data.  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
> name.data 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.

Patch looks correct for me.  It looks a bit fragile though, 
probably we need a bit more bulletproof code here.

More generally - resolver known to leak, and probably requires 
code audit.  It would be fine if you look into it.  I believe 
Artem Bokhan will help with testing (cc'd as I'm not sure he is on 
English list).

Maxim Dounin





More information about the nginx mailing list