Leaking Handles in Custom Debugger

This is a discussion on Leaking Handles in Custom Debugger within the Windows Programming forums, part of the Platform Specific Boards category; Hi, I am trying to code a custom debugger. So after CreateProcess(), I use WaitForDebugEvent(). I observed that in every ...

  1. #1
    Registered User
    Join Date
    Aug 2012
    Posts
    1

    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);
    }

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,651
    Yay for cross-posters!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Objective C Leaking
    By EVOEx in forum Tech Board
    Replies: 3
    Last Post: 09-10-2010, 09:22 AM
  2. Am I leaking?
    By carrotcake1029 in forum C++ Programming
    Replies: 15
    Last Post: 07-16-2009, 04:09 AM
  3. STL leaking?
    By g4j31a5 in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2009, 01:47 AM
  4. Leaking
    By shiver in forum Tech Board
    Replies: 4
    Last Post: 07-05-2006, 07:22 AM
  5. AfxBeginThead leaking or not...
    By playwin in forum Windows Programming
    Replies: 3
    Last Post: 01-07-2005, 10:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21