C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 31st, 2012, 01:17 PM
$angela $angela is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 2 $angela User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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);
}

Reply With Quote
  #2  
Old August 31st, 2012, 01:51 PM
ptr2void ptr2void is offline
I haz teh codez!
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2003
Posts: 2,476 ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level)ptr2void User rank is General 18th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 5 h 26 m 43 sec
Reputation Power: 2194
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!

Reply With Quote
  #3  
Old August 31st, 2012, 06:43 PM
$angela $angela is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2012
Posts: 2 $angela User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Leaking Handles in Custom Debugger

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap