public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: pthread: Fix handle leak in pthread_once.
@ 2024-01-24 13:44 Takashi Yano
  2024-01-24 14:40 ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Takashi Yano @ 2024-01-24 13:44 UTC (permalink / raw)
  To: cygwin-patches; +Cc: Takashi Yano, Corinna Vinschen

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>
---
 winsup/cygwin/thread.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
index 7bb4f9fc8..0f8327831 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);
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Cygwin: pthread: Fix handle leak in pthread_once.
  2024-01-24 13:44 [PATCH] Cygwin: pthread: Fix handle leak in pthread_once Takashi Yano
@ 2024-01-24 14:40 ` Corinna Vinschen
  2024-01-24 14:48   ` Takashi Yano
  0 siblings, 1 reply; 4+ messages in thread
From: Corinna Vinschen @ 2024-01-24 14:40 UTC (permalink / raw)
  To: cygwin-patches

On Jan 24 22:44, Takashi Yano wrote:
> 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>
> ---
>  winsup/cygwin/thread.cc | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/winsup/cygwin/thread.cc b/winsup/cygwin/thread.cc
> index 7bb4f9fc8..0f8327831 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);
> -- 
> 2.43.0

Sure, please push.

(You don't have to CC me, btw., I only get the same mail twice then
and I look into this mailing list constantly anyway)


Thanks,
Corinna

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Cygwin: pthread: Fix handle leak in pthread_once.
  2024-01-24 14:40 ` Corinna Vinschen
@ 2024-01-24 14:48   ` Takashi Yano
  2024-01-24 15:57     ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Takashi Yano @ 2024-01-24 14:48 UTC (permalink / raw)
  To: cygwin-patches

On Wed, 24 Jan 2024 15:40:22 +0100
Corinna Vinschen wrote:
> (You don't have to CC me, btw., I only get the same mail twice then
> and I look into this mailing list constantly anyway)

Perhaps, CC: is added automatically by git send-email if
Reviewed-by: exists. I'll try --no-cc option next time.

Thanks.

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Cygwin: pthread: Fix handle leak in pthread_once.
  2024-01-24 14:48   ` Takashi Yano
@ 2024-01-24 15:57     ` Corinna Vinschen
  0 siblings, 0 replies; 4+ messages in thread
From: Corinna Vinschen @ 2024-01-24 15:57 UTC (permalink / raw)
  To: cygwin-patches

On Jan 24 23:48, Takashi Yano wrote:
> On Wed, 24 Jan 2024 15:40:22 +0100
> Corinna Vinschen wrote:
> > (You don't have to CC me, btw., I only get the same mail twice then
> > and I look into this mailing list constantly anyway)
> 
> Perhaps, CC: is added automatically by git send-email if
> Reviewed-by: exists. I'll try --no-cc option next time.

No worries.  No reason for jumping through hoops, just for an extra
mail.


Thanks,
Corinna

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-24 15:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-24 13:44 [PATCH] Cygwin: pthread: Fix handle leak in pthread_once Takashi Yano
2024-01-24 14:40 ` Corinna Vinschen
2024-01-24 14:48   ` Takashi Yano
2024-01-24 15:57     ` Corinna Vinschen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).