Subject: A Windows handle leak in ares_init

A Windows handle leak in ares_init

From: Shmulik Regev <shmulbox_at_gmail.com>
Date: 2005-06-29

Gentlemen,

I've found a Windows handle leak in c-ares init sequence (I'm using version 1.21). The
following loop for example, will leak exactly N handles (reported by Process Explorer as
\Device\TCP handles)

        for (int i=0; i<N; ++i) {
                ares_channel c;
                if ( ares_init(&c)==ARES_SUCCESS )
                        ares_destroy(c);
        }

I debugged it and as it turns out the call to GetNetworkParams (in the function
get_iphlpapi_dns_info) leaks a handle. I couldn't figure out how to deallocate it using
standard Windows API (admittedly I wasn't thorough in my searching for it). Possibly, it
is not intended to be frequently called. If so, I would assume there are two work-arounds:
1. modify the ares_init code to cache the result and share it among channels
2. allocate a fixed number of channels and reuse them.

Cheers,
Shmulik Regev
Blue Security Ltd.
_______________________________________________
http://cool.haxx.se/mailman/listinfo/c-ares
Received on Wed Jun 29 07:58:54 2005