[commit: ghc] master: Close some handle leaks (#5604) (dad0d22)
Simon Marlow
marlowsd at gmail.com
Wed Nov 9 10:16:12 CET 2011
Repository : ssh://darcs.haskell.org//srv/darcs/ghc
On branch : master
http://hackage.haskell.org/trac/ghc/changeset/dad0d225ec5117b715efc0c44c4fa0d606660381
>---------------------------------------------------------------
commit dad0d225ec5117b715efc0c44c4fa0d606660381
Author: Simon Marlow <marlowsd at gmail.com>
Date: Tue Nov 8 16:28:57 2011 +0000
Close some handle leaks (#5604)
Also, use the Win32 API (CreateThread) instead of the CRT API
(_beginthreadex) for thread creation.
>---------------------------------------------------------------
rts/win32/OSThreads.c | 30 +++++++++++++++++++++---------
1 files changed, 21 insertions(+), 9 deletions(-)
diff --git a/rts/win32/OSThreads.c b/rts/win32/OSThreads.c
index 44db42f..c85dd2f 100644
--- a/rts/win32/OSThreads.c
+++ b/rts/win32/OSThreads.c
@@ -93,20 +93,30 @@ yieldThread()
void
shutdownThread()
{
- _endthreadex(0);
- barf("_endthreadex returned"); // avoid gcc warning
+ ExitThread(0);
+ barf("ExitThread() returned"); // avoid gcc warning
}
int
createOSThread (OSThreadId* pId, OSThreadProc *startProc, void *param)
{
-
- return (_beginthreadex ( NULL, /* default security attributes */
- 0,
- (unsigned (__stdcall *)(void *)) startProc,
- param,
- 0,
- (unsigned*)pId) == 0);
+ HANDLE h;
+ h = CreateThread ( NULL, /* default security attributes */
+ 0,
+ (LPTHREAD_START_ROUTINE)startProc,
+ param,
+ 0,
+ pId);
+
+ if (h == 0) {
+ return 1;
+ } else {
+ // This handle leaks if we don't close it here. Perhaps we
+ // should try to keep it around to avoid needing OpenThread()
+ // later.
+ CloseHandle(h);
+ return 0;
+ }
}
OSThreadId
@@ -128,6 +138,7 @@ osThreadIsAlive(OSThreadId id)
sysErrorBelch("osThreadIsAlive: GetExitCodeThread");
stg_exit(EXIT_FAILURE);
}
+ CloseHandle(hdl);
return (exit_code == STILL_ACTIVE);
}
@@ -286,6 +297,7 @@ interruptOSThread (OSThreadId id)
} else {
// Nothing to do, unfortunately
}
+ CloseHandle(hdl);
}
#else /* !defined(THREADED_RTS) */
More information about the Cvs-ghc
mailing list