From 8894ea48fd4f124c2c93ddca57c95871b3e81258 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Thu, 25 Aug 2016 09:36:43 +0000 Subject: fix for a major handle leak introduced in rev #15740 git-svn-id: http://svn.miranda-ng.org/main/trunk@17206 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/mir_core/src/threads.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/mir_core/src/threads.cpp b/src/mir_core/src/threads.cpp index 91d4c281b7..f4e247e65c 100644 --- a/src/mir_core/src/threads.cpp +++ b/src/mir_core/src/threads.cpp @@ -96,7 +96,7 @@ static LIST threads(10, NumericKeySortT); struct FORK_ARG { - HANDLE hEvent; + HANDLE hEvent, hThread; union { pThreadFunc threadcode; @@ -113,15 +113,14 @@ DWORD WINAPI forkthread_r(void *arg) FORK_ARG *fa = (FORK_ARG*)arg; pThreadFunc callercode = fa->threadcode; void *cookie = fa->arg; + CloseHandle(fa->hThread); Thread_Push((HINSTANCE)callercode); SetEvent(fa->hEvent); callercode(cookie); - HANDLE hThread = GetCurrentThread(); - SetThreadPriority(hThread, THREAD_PRIORITY_TIME_CRITICAL); + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); Thread_Pop(); - CloseHandle(hThread); return 0; } @@ -133,12 +132,12 @@ MIR_CORE_DLL(HANDLE) mir_forkthread(void(__cdecl *threadcode)(void*), void *arg) fa.arg = arg; DWORD threadID; - HANDLE hThread = CreateThread(NULL, 0, forkthread_r, &fa, 0, &threadID); - if (hThread != NULL) + fa.hThread = CreateThread(NULL, 0, forkthread_r, &fa, 0, &threadID); + if (fa.hThread != NULL) WaitForSingleObject(fa.hEvent, INFINITE); CloseHandle(fa.hEvent); - return hThread; + return fa.hThread; } ///////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3