summaryrefslogtreecommitdiff
path: root/compat
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2023-01-23 13:39:51 -0800
committerJunio C Hamano <gitster@pobox.com>2023-01-23 13:39:51 -0800
commit6e0f966efe3d5950e5d9bdfe82425cc4c93bcc5c (patch)
tree9ea2639add3c52479eedca412879d5762035b5cd /compat
parent5427bb4893e29a9502bbee5aed84c3b26e1a4e15 (diff)
parent238a9dfe86d18214bc0b8be079feee01a2fdc407 (diff)
downloadgit-6e0f966efe3d5950e5d9bdfe82425cc4c93bcc5c.tar.gz
Merge branch 'sk/win32-close-handle-upon-pthread-join'
Pthread emulation on Win32 leaked thread handle when a thread is joined. * sk/win32-close-handle-upon-pthread-join: win32: close handles of threads that have been joined win32: prepare pthread.c for change by formatting
Diffstat (limited to 'compat')
-rw-r--r--compat/win32/pthread.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/compat/win32/pthread.c b/compat/win32/pthread.c
index 2e7eead42c..85f8f7920c 100644
--- a/compat/win32/pthread.c
+++ b/compat/win32/pthread.c
@@ -22,12 +22,12 @@ static unsigned __stdcall win32_start_routine(void *arg)
}
int pthread_create(pthread_t *thread, const void *unused,
- void *(*start_routine)(void*), void *arg)
+ void *(*start_routine)(void *), void *arg)
{
thread->arg = arg;
thread->start_routine = start_routine;
- thread->handle = (HANDLE)
- _beginthreadex(NULL, 0, win32_start_routine, thread, 0, NULL);
+ thread->handle = (HANDLE)_beginthreadex(NULL, 0, win32_start_routine,
+ thread, 0, NULL);
if (!thread->handle)
return errno;
@@ -39,14 +39,17 @@ int win32_pthread_join(pthread_t *thread, void **value_ptr)
{
DWORD result = WaitForSingleObject(thread->handle, INFINITE);
switch (result) {
- case WAIT_OBJECT_0:
- if (value_ptr)
- *value_ptr = thread->arg;
- return 0;
- case WAIT_ABANDONED:
- return EINVAL;
- default:
- return err_win_to_posix(GetLastError());
+ case WAIT_OBJECT_0:
+ if (value_ptr)
+ *value_ptr = thread->arg;
+ CloseHandle(thread->handle);
+ return 0;
+ case WAIT_ABANDONED:
+ CloseHandle(thread->handle);
+ return EINVAL;
+ default:
+ /* the wait failed, so do not detach */
+ return err_win_to_posix(GetLastError());
}
}