Niranjan G
Niranjan G

Reputation: 41

Handle leak is observed when a process is run in combination with other process

One of my executable is opening about 330 handles when it is run alone. Where as when it is run in combination with another specific process, it is leaking many handles.

I have used 'handle' utility from sysinternals to check what are all the handles open in both cases. When this process is run in combination with other specific process it is having the following handle entry's extra.

  578: Process       
  57C: Thread        
  580: Process       
  584: Thread        
  588: Process       
  58C: Thread        
  590: Event         
  598: Process       
  59C: Thread        
  5A0: Process       
  5A4: Thread        
  5A8: Process       
  5AC: Thread        
  5B0: Process       
  5B4: Thread        
  5B8: Event        

This way it has 400 extra handles opened for Process, Thread, Event. Eventually this leak is causing the application to crash.

I am new to windows programming, please excuse me I am asking very basic questions. I will really appreciate any help/ suggestion in this regard.

  1. What does the handle 'Process' indicate or mean, in what case it will be opened?
  2. What does the handle 'Thread' indicate or mean, in what case it will be opened?
  3. Why combination of the two processes alone causing the handle leak? (these Processes are mostly independent)
  4. What can I try to understand this behavior?
  5. Any suggestions on how to debug this kind of situation?
  6. Any useful tools to understand further?

Upvotes: 2

Views: 3156

Answers (1)

Hans Passant
Hans Passant

Reputation: 941455

It's a pretty classic bug when using the CreateProcess() function. The last argument, lpProcessInformation, gives you a PROCESS_INFORMATION back. You have to call CloseHandle() on the returned hProcess and hThread members if you are not interested in them.

Upvotes: 10

Related Questions