comphelper/source/misc/compbase.cxx | 6 ------ cppuhelper/source/compbase.cxx | 6 ------ cppuhelper/source/implbase_ex.cxx | 6 ------ cppuhelper/source/weak.cxx | 14 +++++--------- include/comphelper/proparrhlp.hxx | 9 +++------ 5 files changed, 8 insertions(+), 33 deletions(-)
New commits: commit a1a3fd98dcb3c9336eeaffe1d9def7c3ca8c699b Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Sun Nov 17 19:48:42 2024 +0000 Commit: Stephan Bergmann <stephan.bergm...@allotropia.de> CommitDate: Fri Jan 17 09:34:24 2025 +0100 cid#1555986 Check of thread-shared field evades lock acquisition and cid#1556190 Check of thread-shared field evades lock acquisition cid#1555295 Check of thread-shared field evades lock acquisition cid#1608596 Check of thread-shared field evades lock acquisition cid#1555236 Check of thread-shared field evades lock acquisition Double-checked locking pattern Change-Id: Id5cba26750bbd9c7e0248181f636ff653ada5654 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176739 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de> diff --git a/comphelper/source/misc/compbase.cxx b/comphelper/source/misc/compbase.cxx index eafabb013937..02efae8b71c4 100644 --- a/comphelper/source/misc/compbase.cxx +++ b/comphelper/source/misc/compbase.cxx @@ -97,7 +97,6 @@ static bool td_equals(typelib_TypeDescriptionReference const* pTDR1, static cppu::type_entry* getTypeEntries(cppu::class_data* cd) { cppu::type_entry* pEntries = cd->m_typeEntries; - if (!cd->m_storedTypeRefs) // not inited? { static std::mutex aMutex; std::scoped_lock guard(aMutex); @@ -122,14 +121,9 @@ static cppu::type_entry* getTypeEntries(cppu::class_data* cd) // ref is statically held by getCppuType() pEntry->m_type.typeRef = rType.getTypeLibType(); } - OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); cd->m_storedTypeRefs = true; } } - else - { - OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); - } return pEntries; } diff --git a/cppuhelper/source/compbase.cxx b/cppuhelper/source/compbase.cxx index ed4909b71106..aca77677a0f4 100644 --- a/cppuhelper/source/compbase.cxx +++ b/cppuhelper/source/compbase.cxx @@ -81,7 +81,6 @@ static bool td_equals(typelib_TypeDescriptionReference const* pTDR1, static cppu::type_entry* getTypeEntries(cppu::class_data* cd) { cppu::type_entry* pEntries = cd->m_typeEntries; - if (!cd->m_storedTypeRefs) // not inited? { static std::mutex aMutex; std::scoped_lock guard(aMutex); @@ -106,14 +105,9 @@ static cppu::type_entry* getTypeEntries(cppu::class_data* cd) // ref is statically held by getCppuType() pEntry->m_type.typeRef = rType.getTypeLibType(); } - OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); cd->m_storedTypeRefs = true; } } - else - { - OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); - } return pEntries; } diff --git a/cppuhelper/source/implbase_ex.cxx b/cppuhelper/source/implbase_ex.cxx index 3f88feb97dd1..9d3e03412737 100644 --- a/cppuhelper/source/implbase_ex.cxx +++ b/cppuhelper/source/implbase_ex.cxx @@ -64,7 +64,6 @@ static bool td_equals( static type_entry * getTypeEntries( class_data * cd ) { type_entry * pEntries = cd->m_typeEntries; - if (! cd->m_storedTypeRefs) // not inited? { static std::mutex aMutex; std::scoped_lock guard( aMutex ); @@ -86,14 +85,9 @@ static type_entry * getTypeEntries( class_data * cd ) // ref is statically held by getCppuType() pEntry->m_type.typeRef = rType.getTypeLibType(); } - OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); cd->m_storedTypeRefs = true; } } - else - { - OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); - } return pEntries; } diff --git a/cppuhelper/source/weak.cxx b/cppuhelper/source/weak.cxx index 446cdc0e43ba..07fe1cbad359 100644 --- a/cppuhelper/source/weak.cxx +++ b/cppuhelper/source/weak.cxx @@ -254,16 +254,12 @@ OWeakObject::~OWeakObject() COVERITY_NOEXCEPT_FALSE // XWeak Reference< XAdapter > SAL_CALL OWeakObject::queryAdapter() { - if (!m_pWeakConnectionPoint) + std::scoped_lock aGuard( *gpWeakMutex ); + if( !m_pWeakConnectionPoint ) { - // only acquire mutex if member is not created - std::scoped_lock aGuard( *gpWeakMutex ); - if( !m_pWeakConnectionPoint ) - { - OWeakConnectionPoint * p = new OWeakConnectionPoint(this); - p->acquire(); - m_pWeakConnectionPoint = p; - } + OWeakConnectionPoint * p = new OWeakConnectionPoint(this); + p->acquire(); + m_pWeakConnectionPoint = p; } return m_pWeakConnectionPoint; diff --git a/include/comphelper/proparrhlp.hxx b/include/comphelper/proparrhlp.hxx index 77fa9e1b9714..9093ff579f0c 100644 --- a/include/comphelper/proparrhlp.hxx +++ b/include/comphelper/proparrhlp.hxx @@ -112,14 +112,11 @@ template <class TYPE> ::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper<TYPE>::getArrayHelper() { OSL_ENSURE(s_nRefCount, "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !"); + std::unique_lock aGuard(theMutex()); if (!s_pProps) { - std::unique_lock aGuard(theMutex()); - if (!s_pProps) - { - s_pProps = createArrayHelper(); - OSL_ENSURE(s_pProps, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !"); - } + s_pProps = createArrayHelper(); + OSL_ENSURE(s_pProps, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !"); } return s_pProps; }