From 111ec9a98945cd50b0de140c0f22d5cfe4831ab1 Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Mon, 26 Aug 2024 12:25:50 -0700 Subject: [PATCH] Fix bug we added to *NSYNC a while ago This is believed to fix a crash, that's possible in nsync_waiter_free_() when you call pthread_cond_timedwait(), or nsync_cv_wait_with_deadline() where an assertion can fail. Thanks ipv4.games for helping me find this! --- third_party/nsync/mem/nsync_cv.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/third_party/nsync/mem/nsync_cv.c b/third_party/nsync/mem/nsync_cv.c index 8e363f77c..a85fb67d2 100644 --- a/third_party/nsync/mem/nsync_cv.c +++ b/third_party/nsync/mem/nsync_cv.c @@ -233,7 +233,9 @@ static int nsync_cv_wait_with_deadline_impl_ (struct nsync_cv_wait_with_deadline /* Requeue on *pmu using existing waiter struct; current thread is the designated waker. */ nsync_mu_lock_slow_ (c->cv_mu, c->w, MU_DESIG_WAKER, c->w->l_type); + nsync_waiter_free_ (c->w); } else { + nsync_waiter_free_ (c->w); /* Traditional case: We've woken from the cv, and need to reacquire *pmu. */ if (c->is_reader_mu) { nsync_mu_rlock (c->cv_mu); @@ -241,7 +243,6 @@ static int nsync_cv_wait_with_deadline_impl_ (struct nsync_cv_wait_with_deadline (*c->lock) (c->pmu); } } - nsync_waiter_free_ (c->w); IGNORE_RACES_END (); return (outcome); }