cprogrammer
cprogrammer

Reputation: 5675

CreateThread handle leak

CreateThread returns a HANDLE object that need to be closed by CloseHandle

The documentation states that The thread object remains in the system until the thread has terminated and all handles to it have been closed through a call to CloseHandle.

My question is what happens if the return variable is not used. It equals with not closing returned handle and because of this with a handle leak? It's that correct ?

Upvotes: 2

Views: 2172

Answers (1)

Alok Save
Alok Save

Reputation: 206528

It equals with not closing returned handle and because of this with a handle leak? It's that correct ?

Yes, You will be leaking Operating system resources, this is analogous to leaking memory when you have a memory leak.

Reference:
MSDN Documentation:

Closing a thread handle does not terminate the associated thread or remove the thread object. Closing a process handle does not terminate the associated process or remove the process object. To remove a thread object, you must terminate the thread, then close all handles to the thread.

Upvotes: 4

Related Questions