Cygwin: pthread: Fix handle leak in pthread_once.

If pthread_once() is called with pthread_once_t initialized using
PTREAD_ONCE_INIT, pthread_once does not release pthread_mutex used
internally. This patch fixes that by calling pthread_mutex_destroy()
in the thread which has called init_routine.

Reviewed-by: Corinna Vinschen <corinna@vinschen.de>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
This commit is contained in:
Takashi Yano 2024-01-24 22:33:12 +09:00
parent 15140d6df6
commit 2c5433e5da
1 changed files with 3 additions and 0 deletions

View File

@ -2060,6 +2060,9 @@ pthread::once (pthread_once_t *once_control, void (*init_routine) (void))
{
init_routine ();
once_control->state = 1;
pthread_mutex_unlock (&once_control->mutex);
while (pthread_mutex_destroy (&once_control->mutex) == EBUSY);
return 0;
}
/* Here we must remove our cancellation handler */
pthread_mutex_unlock (&once_control->mutex);