From 94c1597c9fb17fcbca21168c18e9056315f081fe Mon Sep 17 00:00:00 2001 From: khizmax Date: Sat, 28 Nov 2015 13:25:38 +0300 Subject: [PATCH] Fixed rare double-free in DHP SMR --- cds/gc/details/dhp.h | 4 +++- src/dhp_gc.cpp | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cds/gc/details/dhp.h b/cds/gc/details/dhp.h index 14c52a3f..5825a9cc 100644 --- a/cds/gc/details/dhp.h +++ b/cds/gc/details/dhp.h @@ -297,11 +297,13 @@ namespace cds { namespace gc { privatize_result privatize() CDS_NOEXCEPT { privatize_result res; - res.first = m_pHead.exchange( nullptr, atomics::memory_order_acq_rel ); // Item counter is needed only as a threshold for \p scan() function // So, we may clear the item counter without synchronization with m_pHead res.second = m_nItemCount.exchange( 0, atomics::memory_order_relaxed ); + + res.first = m_pHead.exchange( nullptr, atomics::memory_order_acq_rel ); + return res; } diff --git a/src/dhp_gc.cpp b/src/dhp_gc.cpp index cdafe5de..a5d22487 100644 --- a/src/dhp_gc.cpp +++ b/src/dhp_gc.cpp @@ -19,11 +19,11 @@ namespace cds { namespace gc { namespace dhp { size_t const m_nBucketCount; item_type * m_Buckets; - item_type& bucket( retired_ptr_node& node ) + item_type& bucket( retired_ptr_node& node ) const { return bucket( node.m_ptr.m_p ); } - item_type& bucket( guard_data::guarded_ptr p ) + item_type& bucket( guard_data::guarded_ptr p ) const { return m_Buckets[ std::hash()( p ) & (m_nBucketCount - 1) ]; } -- 2.34.1