Re: Event handle leak
- From: "Oleg Starodumov" <com-dot-debuginfo-at-oleg>
- Date: Thu, 3 Nov 2005 17:47:55 +0200
> My multithread application leaks handle. But only when called from a while
> loop with no sleep.
> So the problem is, if I try to step in through the debugger theres no handle
> leak.
>
> The leaking handle according to ProcessExplorer is of type "Event".
>
> With ProcessExplorer I have the following information about the handle:
> 1. Handle Address
> 2. Access Address
> 3. Object Address
>
> So with this informations any way to break the code when the leaked event is
> created.
If you can test on Windows XP or 2003 (preferrably XP-SP2 or 2K3-SP1),
you can use handle tracing embedded into the OS to get call stacks at the moment
when a handle was created. This can be done with the help of WinDbg and related tools:
http://www.microsoft.com/whdc/devtools/debugging/default.mspx
If you can reproduce the problem when running the application under debugger
(WinDbg), run "!htrace -enable" command when you want to start tracing handles.
Then, after you see that handles are leaking, break into debugger
and use "!htrace <handle>" to display the call stack for the suspected handle
(use the real handle value in place of <handle>; 0 can be used to dump all handles).
If the problem cannot be reproduced under debugger, you can access the call stacks
noninvasively using these commands:
Enable tracing:
> cdb -pv -p <pid> -c "!htrace -enable;q"
Show call stack for a handle:
> cdb -pv -p <pid> -c "!htrace <handle>;q"
(<pid> means process id of the target process; access to good symbols for system DLLs
is needed, see Symbols section in WinDbg docs about symbol server etc.)
On earlier operating systems, you can try to trace calls to CreateEvent and record the call stack,
again with WinDbg, with a command like:
> bp kernel32!CreateEventW "kb;g"
(it will create a tracing breakpoint, which, when hit, will display the function parameters and
the call stack at the moment when the event was created and let the process continue, so you
can later use this information to find the source of the leaked event)
And of course another way is to use a product that can test your application
for resource leaks (e.g. see softwareverify.com).
Regards,
Oleg
[VC++ MVP]
.
- References:
- Event handle leak
- From: Suhredayan
- Event handle leak
- Prev by Date: Event handle leak
- Next by Date: Re: script debugger
- Previous by thread: Event handle leak
- Index(es):
Relevant Pages
|