From 695a46783e7dfd7cee0e083d9a8c2864dd7ac884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Tue, 24 Sep 2024 21:18:20 +0100 Subject: [PATCH] cid#1606918 Data race condition MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and cid#1606991 Data race condition cid#1607010 Data race condition cid#1607323 Data race condition cid#1607335 Data race condition cid#1607635 Data race condition cid#1608162 Data race condition Change-Id: I65edcf08f92fb564d56d0e8954212533c1cbec91 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173895 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- stoc/source/inspect/introspection.cxx | 46 ++++++++++----------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/stoc/source/inspect/introspection.cxx b/stoc/source/inspect/introspection.cxx index 046063a0a2ae..716e35c95df1 100644 --- a/stoc/source/inspect/introspection.cxx +++ b/stoc/source/inspect/introspection.cxx @@ -685,8 +685,8 @@ class ImplIntrospectionAccess : public IntrospectionAccessHelper Reference getXEnumerationAccess(); Reference getXIdlArray(); - void cacheXNameContainer(); - void cacheXIndexContainer(); + void cacheXNameContainer(const std::unique_lock& rGuard); + void cacheXIndexContainer(const std::unique_lock& rGuard); public: ImplIntrospectionAccess( Any obj, rtl::Reference< IntrospectionAccessStatic_Impl > pStaticImpl_ ); @@ -797,7 +797,7 @@ Reference ImplIntrospectionAccess::getXElementAccess() return mxObjElementAccess; } -void ImplIntrospectionAccess::cacheXNameContainer() +void ImplIntrospectionAccess::cacheXNameContainer(const std::unique_lock& /*rGuard*/) { Reference xNameContainer; Reference xNameReplace; @@ -819,7 +819,6 @@ void ImplIntrospectionAccess::cacheXNameContainer() } { - std::unique_lock aGuard( m_aMutex ); if( !mxObjNameContainer.is() ) mxObjNameContainer = xNameContainer; if( !mxObjNameReplace.is() ) @@ -834,10 +833,8 @@ Reference ImplIntrospectionAccess::getXNameContainer() std::unique_lock aGuard( m_aMutex ); if( !mxObjNameContainer.is() ) - { - aGuard.unlock(); - cacheXNameContainer(); - } + cacheXNameContainer(aGuard); + return mxObjNameContainer; } @@ -846,10 +843,8 @@ Reference ImplIntrospectionAccess::getXNameReplace() std::unique_lock aGuard( m_aMutex ); if( !mxObjNameReplace.is() ) - { - aGuard.unlock(); - cacheXNameContainer(); - } + cacheXNameContainer(aGuard); + return mxObjNameReplace; } @@ -858,14 +853,12 @@ Reference ImplIntrospectionAccess::getXNameAccess() std::unique_lock aGuard( m_aMutex ); if( !mxObjNameAccess.is() ) - { - aGuard.unlock(); - cacheXNameContainer(); - } + cacheXNameContainer(aGuard); + return mxObjNameAccess; } -void ImplIntrospectionAccess::cacheXIndexContainer() +void ImplIntrospectionAccess::cacheXIndexContainer(const std::unique_lock& /*rGuard*/) { Reference xIndexContainer; Reference xIndexReplace; @@ -887,7 +880,6 @@ void ImplIntrospectionAccess::cacheXIndexContainer() } { - std::unique_lock aGuard( m_aMutex ); if( !mxObjIndexContainer.is() ) mxObjIndexContainer = xIndexContainer; if( !mxObjIndexReplace.is() ) @@ -902,10 +894,8 @@ Reference ImplIntrospectionAccess::getXIndexContainer() std::unique_lock aGuard( m_aMutex ); if( !mxObjIndexContainer.is() ) - { - aGuard.unlock(); - cacheXIndexContainer(); - } + cacheXIndexContainer(aGuard); + return mxObjIndexContainer; } @@ -914,10 +904,8 @@ Reference ImplIntrospectionAccess::getXIndexReplace() std::unique_lock aGuard( m_aMutex ); if( !mxObjIndexReplace.is() ) - { - aGuard.unlock(); - cacheXIndexContainer(); - } + cacheXIndexContainer(aGuard); + return mxObjIndexReplace; } @@ -926,10 +914,8 @@ Reference ImplIntrospectionAccess::getXIndexAccess() std::unique_lock aGuard( m_aMutex ); if( !mxObjIndexAccess.is() ) - { - aGuard.unlock(); - cacheXIndexContainer(); - } + cacheXIndexContainer(aGuard); + return mxObjIndexAccess; }