From 43003176311ddbd6abaf0e5d15b0967506cb8d3b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 31 May 2013 23:20:58 +0000 Subject: [PATCH] Make wxSharedPtr::Release() really MT-safe. Using wxAtomicDec() is not enough, its result also must be checked as it will return 0 only in one of the threads if multiple threads call it in parallel, while the old test for m_count==0 could pass for more than one thread, resulting in deleting the same pointer more than once. Closes #15227. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74065 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/sharedptr.h | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index f64bc4e691..4eba8dbd67 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -596,6 +596,7 @@ All: - Add wxSocketBase::GetSocket() (Laurent Poujoulat). - Add IEEE 754 single/double precision support to wxDataStream classes (net147). - Add wxVector<>::const_reverse_iterator (troelsk). +- Fix thread-safety issue in wxSharedPtr<> (plorkyeran). - Add Nepali translation (Him Prasad Gautam). All (GUI): diff --git a/include/wx/sharedptr.h b/include/wx/sharedptr.h index 279e29b3a3..290c610adc 100644 --- a/include/wx/sharedptr.h +++ b/include/wx/sharedptr.h @@ -115,8 +115,7 @@ private: { if (m_ref) { - wxAtomicDec( m_ref->m_count ); - if (m_ref->m_count == 0) + if (!wxAtomicDec( m_ref->m_count )) { delete m_ref->m_ptr; delete m_ref; -- 2.45.2