From c99729093af33b97b190eed8da84dd28ee61b25f Mon Sep 17 00:00:00 2001 From: Alexander Boettcher Date: Fri, 7 Oct 2016 19:59:18 +0200 Subject: [PATCH] base: fix race in multiple lock.unlock() calls Fixes #2122 --- repos/base/src/lib/base/lock.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/repos/base/src/lib/base/lock.cc b/repos/base/src/lib/base/lock.cc index 447062ee7e..b358496304 100644 --- a/repos/base/src/lib/base/lock.cc +++ b/repos/base/src/lib/base/lock.cc @@ -146,12 +146,16 @@ void Cancelable_lock::unlock() /* transfer lock ownership to next applicant and wake him up */ _owner = *next_owner; + + /* make copy since _owner may change outside spinlock ! */ + Applicant owner = *next_owner; + if (_last_applicant == next_owner) _last_applicant = &_owner; spinlock_unlock(&_spinlock_state); - _owner.wake_up(); + owner.wake_up(); } else {