Re: GetNetworkParams leak ?(WAS: \\device\tcp handle leak)

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Tom,

Tom Goff wrote:
Hi Shmul,

I have found that your leak is related to dynamically loading the DLL.
The following code does not leak handles:

static void test_get_networks_params(int N)
{
	for (int i=0; i<N; ++i )
	{
		FIXED_INFO *fi = (FIXED_INFO*)alloca (sizeof(*fi));
		DWORD size = sizeof (*fi);

		GetNetworkParams(fi, &size);
	}
}


Completely off-topic but I thought it might hurt you one day if nobody tells you: You should never ever call alloca in a loop, as this might cause your stack to be blown. In the code above it will probably much better if you just create one FIXED_INFO on the stack that you use for every cycle in the for-loop.


As a side note: If you run this code through VS2005 with prefast enabled, it will immediately spot this error.

HTH,

--
Stefan Kuhr

"Lesen schadet der Dummheit"
.



Relevant Pages

  • Re: GetNetworkParams leak ?(WAS: \device cp handle leak)
    ... I have found that your leak is related to dynamically loading the DLL. ... static void test_get_networks_params6 ...
    (microsoft.public.win32.programmer.kernel)
  • Re: STA cannot prevent multiple client calls accessing at the same time??
    ... making a cross-apartment call from an STA. ... DLL object runs on. ... As for the suddenly changing call stack - that's a debugger quirk - ... And maybe I am not an Appz ...
    (microsoft.public.vc.atl)
  • Re: AD+ crash logs and .dmps Part II
    ... This a .dll provided by an online payment verification ... The Debugger docs have some basic info but overall, understanding ... details the formation and usage of the stack. ...
    (microsoft.public.inetserver.iis.security)
  • Re: tracking down error in MFC42.dll
    ... (I used WinDbg to do that, but the same can be done ... The same could be done for your dll if it would be built with debug ... If you put symbols of your dll on the target system (in the same ... what the call stack shows. ...
    (microsoft.public.vc.mfc)
  • Win32 DLL project randomly crashes after moving to VS2005
    ... the first step was to take care of the compilation ... The problem is that when I run my DLL it crashes in apparently random places ... I had a crash within a dialog's window procedure and another ... image library were generating a "stack overflow" message. ...
    (microsoft.public.vstudio.general)