winpr: CloseHandle did not release the thread TCB

This resulted in huge memory leaks - 8MB per thread, depending on
the system's default stack size.
The leak happend even if CloseHandle() was correctly used to "detach"
the thread but WaitForSingleObject was never called.
This commit is contained in:
Norbert Federa 2014-07-10 12:28:35 +02:00
parent 1d8e2fc95f
commit aac57e7e72
2 changed files with 5 additions and 0 deletions

View File

@ -139,6 +139,9 @@ BOOL CloseHandle(HANDLE hObject)
WINPR_THREAD* thread;
thread = (WINPR_THREAD*) Object;
if (thread->started) {
pthread_detach(thread->thread);
}
free(thread);
return TRUE;

View File

@ -255,6 +255,8 @@ DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)
else
status = pthread_join(thread->thread, &thread_status);
thread->started = FALSE;
if (status != 0)
{
fprintf(stderr, "WaitForSingleObject: pthread_join failure: [%d] %s\n",