Skip to content

Commit

Permalink
Cygwin: pthread: Fix handle leak in pthread_once.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tyan0 committed Jan 24, 2024
1 parent 15140d6 commit 2c5433e
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions winsup/cygwin/thread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 2c5433e

Please sign in to comment.