The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> C Programming
|
Leaking Handles in Custom Debugger
Discuss Leaking Handles in Custom Debugger in the C Programming forum on Dev Shed. Leaking Handles in Custom Debugger C programming forum discussing all C derivatives, including C#, C++, Object-C, and even plain old vanilla C. These languages are low level languages, and used on projects such as device drivers, compilers, and even whole computer operating systems.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

August 31st, 2012, 01:17 PM
|
|
Registered User
|
|
Join Date: Aug 2012
Posts: 2
Time spent in forums: 33 m 9 sec
Reputation Power: 0
|
|
|
Leaking Handles in Custom Debugger
Hi, I am trying to code a custom debugger. So after CreateProcess(), I use WaitForDebugEvent(). I observed that in every LOAD_DLL_DEBUG_EVENT, a new file handle is created (u.LoadDll.hFile). After the process is terminated, the numerous file handles still remains. Over time, wouldn't this cause a low virtual memory?
The code is straightforward, pasted here.
Thanks for any help.
Code:
bool continueDebugging = true;
if ( CreateProcess( NULL, szProcCmd, NULL, NULL, FALSE, CREATE_NEW_CONSOLE|DEBUG_PROCESS, NULL, NULL, &si, &pi) )
{
while (continueDebugging )
{
memset (&DebugEvent, 0, sizeof(DEBUG_EVENT));
if(WaitForDebugEvent(&DebugEvent, 1000))
{
if (DebugEvent.dwDebugEventCode == CREATE_PROCESS_DEBUG_EVENT)
{
//do something
}
else if (DebugEvent.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT)
{
continueDebugging = false;
}
else if (DebugEvent.dwDebugEventCode == CREATE_THREAD_DEBUG_EVENT)
{
//do something
}
else if (DebugEvent.dwDebugEventCode == EXIT_THREAD_DEBUG_EVENT)
{
//do something
}
else if (DebugEvent.dwDebugEventCode == LOAD_DLL_DEBUG_EVENT)
{
//do something
}
else if (DebugEvent.dwDebugEventCode == UNLOAD_DLL_DEBUG_EVENT)
{
//do something
}
else if (DebugEvent.dwDebugEventCode == OUTPUT_DEBUG_STRING_EVENT)
{
//do something
}
else if (DebugEvent.dwDebugEventCode == RIP_EVENT)
{
//do something
}
else if (DebugEvent.dwDebugEventCode == EXCEPTION_DEBUG_EVENT)
{
//do something
}
else
{
//"Undefined Event!!
}
ContinueDebugEvent( DebugEvent.dwProcessId, DebugEvent.dwThreadId, DBG_CONTINUE);
}
}
DebugActiveProcessStop(pi.dwProcessId);
TerminateProcess(pi.hProcess, );
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
}
|

August 31st, 2012, 01:51 PM
|
|
|
Well, reading the docs:
Quote: | The DEBUG_EVENT structure contains a LOAD_DLL_DEBUG_INFO structure. This structure includes a handle to the newly loaded DLL, the base address of the DLL, and other information that describes the DLL. The debugger should close the handle to the DLL handle while processing LOAD_DLL_DEBUG_EVENT. |
Emphasis mine
__________________
I ♥ ManiacDan & requinix
This is a sig, and not necessarily a comment on the OP:
Please don't be a help vampire!
|

August 31st, 2012, 06:43 PM
|
|
Registered User
|
|
Join Date: Aug 2012
Posts: 2
Time spent in forums: 33 m 9 sec
Reputation Power: 0
|
|
Thank you very much for your reply. I missed that somehow. 
Last edited by $angela : September 1st, 2012 at 09:47 AM.
Reason: Marked as closed
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|