Re: [PATCH] win32: close handles of threads that have been joined
- From
Johannes Sixt <j6t@kdbg.org>
- Date
- Dec 20, 2022, 07:53 UTC
- Message-ID
- <a1d947ba-50ba-331b-daf6-30773d388be4@kdbg.org>
- In-Reply-To
- <pull.1406.git.git.1671474876207.gitgitgadget@gmail.com>
Am 19.12.22 um 19:34 schrieb Rose via GitGitGadget:
Show 7 quoted lines
> From: Seija Kijin <doremylover123@gmail.com> > > After joining threads, the handle to the original thread > should be closed as it no longer needs to be open. > > Signed-off-by: Seija Kijin <doremylover123@gmail.com> > ---
Show 25 quoted lines
> compat/win32/pthread.c | 22 ++++++++++++++--------
> 1 file changed, 14 insertions(+), 8 deletions(-)
>
> diff --git a/compat/win32/pthread.c b/compat/win32/pthread.c
> index 2e7eead42cb..de89667ef70 100644
> --- a/compat/win32/pthread.c
> +++ b/compat/win32/pthread.c
> @@ -39,14 +39,20 @@ 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;
> + /* detach the thread once the join succeeds */
> + CloseHandle(thread->handle);
> + return 0;This is a good change. It is a severe omission that the handle was not closed. (But I still have to test the patch.)
> + case WAIT_ABANDONED: > + /* either thread is not joinable or another thread is waiting on > + * this, so we do not detatch */ > + return EINVAL;
I don't know which cases this mental note wants to help. Assuming that the [win232_]pthread_ API is used correctly, this error cannot happen (WAIT_ABANDONED can only happen when WaitForSingleObject is called on a mutex object).
Show 5 quoted lines
> + default: > + case WAIT_FAILED: > + /* the function failed so we do not detach */ > + return err_win_to_posix(GetLastError()); > }
Good.
-- Hannes