Subject: Re: Leaked handles on Windows

Re: Leaked handles on Windows

From: Shmulik Regev <shmulbox_at_gmail.com>
Date: Wed, 13 May 2009 10:13:20 +0300

Hi,

I'm the author of the 2005 thread you've mentioned. If my memory serves me
right Microsoft had acknowledged that it is a bug - I think they thought it
only happened in Windows 2003, but I've experienced it with XP back then. I
think it wasn't hard to bypass this behavior by caching the results of
GetNetworkParams.

Cheers,
Shmul

On Wed, May 13, 2009 at 10:05 AM, Vlad Dinulescu
<vlad.dinulescu_at_avira.com>wrote:

> Hello,
>
> We had troubles with leaked handles using the c-ares library, on
> Windows. After almost two weeks of digging, we found out that the
> problem lies within ares_init_options(), when calling
> GetNetworkParams(). The call of this function leaves a single open
> handle which is never destroyed until the process terminates. Every
> further call to ares_init_options leaves another open handle. If one
> opens lots of ares channels, lots of handles are being leaked. After
> commenting out the call to GetNetworkParams(), and letting c-ares find
> the nameserver information from registry keys, everything went well,
> without any leaked handles. We're running Windows XP SP2 and Windows XP
> SP3 (same behaviour).
> We also found this thread dating from 2005, which describes the same
> problem:
> http://www.ureader.com/msg/1474561.aspx
>
> Are you aware of this problem?
> What would the best solution (or better said alternative) be?
>
> I thought of:
> a) making Microsoft release a service pack for GetNetworkParams() and
> forcing all users worldwide install it – not doable.
>
> b) commenting out the call to GetNetworkParams and letting c-ares find
> the nameserver information from registry keys. But I am not sure if
> c-ares finds the nameserver information on all versions of Windows. What
> about Vista? Vista 64? Windows 7 ?
> This is the simplest alternative I could come up with, but it would
> need lots of testing.
>
> c) letting c-ares leak a handle , and trying to open as few channels as
> possible (reuse them). This would imply a lot of coding and testing in
> our application, however.
>
> d) maybe something else – in c-ares, trying to get the nameserver
> information from registry keys first and only if that fails, calling
> GetNetworkParams().
>
> e) letting the user set the DNS server information through a callback.
> This would let the user solve the problem :)
>
> I am looking forward to hearing from you!
>
>
> Best regards,
> Vlad Dinulescu
>
Received on 2009-05-13