diff options
author | Michael Stahl <mstahl@redhat.com> | 2016-06-17 13:35:08 +0200 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2016-06-18 20:54:21 +0200 |
commit | a2e6f6907ba5f8bc7c7bd52987b8d1666e27c2cb (patch) | |
tree | bed9a64008e34d6aa6542486c258e743c32f3adf /cppuhelper | |
parent | 4b0fcd451afbb0e52cb8d211c916867dde1203c0 (diff) |
cppuhelper: WeakReference isn't thread-safe
... but its documentation claims that it is, which is partially
misleading, so fix both the documentation and the data race in
WeakReferenceHelper::clear().
This actually crashed in clear() in the multi-threaded ZipPackage code
on exporting the bugdoc from tdf#94212, presumably because clear()
races against OWeakRefListener::dispose().
(cherry picked from commit debe788bcf3ec258b6b95df3db1f7bfeba881be1)
Change-Id: I85665c11b8157e90d15e8263758e24e66efeb86c
Reviewed-on: https://gerrit.libreoffice.org/26427
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Stephan Bergmann <sbergman@redhat.com>
(cherry picked from commit 2051d7b849105c2020887635e18687c30cdc88c7)
Diffstat (limited to 'cppuhelper')
-rw-r--r-- | cppuhelper/source/weak.cxx | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/cppuhelper/source/weak.cxx b/cppuhelper/source/weak.cxx index a67f881ad54a..72b88969715d 100644 --- a/cppuhelper/source/weak.cxx +++ b/cppuhelper/source/weak.cxx @@ -34,6 +34,7 @@ namespace cppu { // due to static Reflection destruction from usr, there must be a mutex leak (#73272#) +// this is used to lock all instances of OWeakConnectionPoint and OWeakRefListener as well as OWeakObject::m_pWeakConnectionPoint inline static Mutex & getWeakMutex() { static Mutex * s_pMutex = nullptr; @@ -333,7 +334,7 @@ public: /// The reference counter. oslInterlockedCount m_aRefCount; - /// The connection point of the weak object + /// The connection point of the weak object, guarded by getWeakMutex() Reference< XAdapter > m_XWeakConnectionPoint; }; @@ -438,12 +439,7 @@ void WeakReferenceHelper::clear() { if (m_pImpl) { - if (m_pImpl->m_XWeakConnectionPoint.is()) - { - m_pImpl->m_XWeakConnectionPoint->removeReference( - static_cast<XReference*>(m_pImpl)); - m_pImpl->m_XWeakConnectionPoint.clear(); - } + m_pImpl->dispose(); m_pImpl->release(); m_pImpl = nullptr; } @@ -488,6 +484,7 @@ Reference< XInterface > WeakReferenceHelper::get() const { Reference< XAdapter > xAdp; { + // must lock to access m_XWeakConnectionPoint MutexGuard guard(cppu::getWeakMutex()); if( m_pImpl && m_pImpl->m_XWeakConnectionPoint.is() ) xAdp = m_pImpl->m_XWeakConnectionPoint; |