aboutsummaryrefslogtreecommitdiff
path: root/winsup
diff options
context:
space:
mode:
authorTakashi Yano <takashi.yano@nifty.ne.jp>2024-01-24 22:33:12 +0900
committerTakashi Yano <takashi.yano@nifty.ne.jp>2024-01-24 22:42:49 +0900
commit2c5433e5da8216aaf7458e50c63683c68fb0d3e8 (patch)
tree67d7bcaafbdaca3d06ca1db489d3ea8496208477 /winsup
parent15140d6df667a71e660dc9da9ca9071fa3c5dbbd (diff)
downloadnewlib-2c5433e5da8216aaf7458e50c63683c68fb0d3e8.zip
newlib-2c5433e5da8216aaf7458e50c63683c68fb0d3e8.tar.gz
newlib-2c5433e5da8216aaf7458e50c63683c68fb0d3e8.tar.bz2
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>
Diffstat (limited to 'winsup')
-rw-r--r--winsup/cygwin/thread.cc3
1 files changed, 3 insertions, 0 deletions
diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index 7bb4f9f..0f83278 100644
--- a/winsup/cygwin/thread.cc
+++ b/winsup/cygwin/thread.cc
@@ -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);