From: Michael Lee Date: Wed, 28 Sep 2016 00:31:22 +0000 (-0700) Subject: Set a default value for slot in SharedMutex.h X-Git-Tag: v2016.10.03.00~12 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=c532329ad0c24fa6ed9f119201ade738a5d623f4;p=folly.git Set a default value for slot in SharedMutex.h Summary: `SharedMutexImpl::lockSharedImpl` has a potentially uninitialized access: Assume state = 0 canAlreadyDefer = (state & kMayDefer) != 0 ==> false aboveDeferThreshold = (state & kHasS) >= (kNumSharedToStartDeferring - 1) * kIncrHasS ==> false if (canAlreadyDefer || (aboveDeferThreshold && !drainInProgress)) ==> false line:1452: gotSlot(slot)->compare_exchange_strong(...) uses slot uninitialized Reviewed By: Orvid Differential Revision: D3933638 fbshipit-source-id: 0fbce5c00b8b1f34e50c302cb88def97853c5afe --- diff --git a/folly/SharedMutex.h b/folly/SharedMutex.h index 24bce0d7..48041c11 100644 --- a/folly/SharedMutex.h +++ b/folly/SharedMutex.h @@ -1390,7 +1390,7 @@ bool SharedMutexImpl:: return false; } - uint32_t slot; + uint32_t slot = tls_lastDeferredReaderSlot; uintptr_t slotValue = 1; // any non-zero value will do bool canAlreadyDefer = (state & kMayDefer) != 0; @@ -1399,7 +1399,6 @@ bool SharedMutexImpl:: bool drainInProgress = ReaderPriority && (state & kBegunE) != 0; if (canAlreadyDefer || (aboveDeferThreshold && !drainInProgress)) { /* Try using the most recent slot first. */ - slot = tls_lastDeferredReaderSlot; slotValue = deferredReader(slot)->load(std::memory_order_relaxed); if (slotValue != 0) { // starting point for our empty-slot search, can change after