comphelper/source/property/genericpropertyset.cxx |    2 +-
 include/comphelper/multiinterfacecontainer4.hxx   |   18 ++++++++++--------
 sfx2/source/control/unoctitm.cxx                  |    2 +-
 ucbhelper/source/provider/resultset.cxx           |    4 ++--
 4 files changed, 14 insertions(+), 12 deletions(-)

New commits:
commit 0fbaff8f022a5d1a09a22dbfc6395c458bfc5bfd
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon Feb 13 18:07:00 2023 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon Feb 13 17:01:04 2023 +0000

    enforce proper locking when calling OInterfaceContainerHelper4
    
    Change-Id: Ic86305f3d16148925c7753200a687f36f08a6516
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146936
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/comphelper/source/property/genericpropertyset.cxx 
b/comphelper/source/property/genericpropertyset.cxx
index b459de64cc6e..a618d1f7c0e4 100644
--- a/comphelper/source/property/genericpropertyset.cxx
+++ b/comphelper/source/property/genericpropertyset.cxx
@@ -142,7 +142,7 @@ void GenericPropertySet::_setPropertyValues( const 
PropertyMapEntry** ppEntries,
 
     while( *ppEntries )
     {
-        OInterfaceContainerHelper4<XPropertyChangeListener> * pHelper = 
m_aListener.getContainer((*ppEntries)->maName);
+        OInterfaceContainerHelper4<XPropertyChangeListener> * pHelper = 
m_aListener.getContainer(aGuard, (*ppEntries)->maName);
 
         maAnyMap[ (*ppEntries)->maName ] = *pValues;
 
diff --git a/include/comphelper/multiinterfacecontainer4.hxx 
b/include/comphelper/multiinterfacecontainer4.hxx
index eeccd20920ca..1241951f5505 100644
--- a/include/comphelper/multiinterfacecontainer4.hxx
+++ b/include/comphelper/multiinterfacecontainer4.hxx
@@ -54,11 +54,11 @@ public:
                 aInterfaceTypes.push_back(rPair.first);
         return aInterfaceTypes;
     }
-    inline bool hasContainedTypes() const
+    inline bool hasContainedTypes(std::unique_lock<std::mutex>& rGuard) const
     {
         for (const auto& rPair : m_aMap)
             // are interfaces added to this container?
-            if (rPair.second->getLength())
+            if (rPair.second->getLength(rGuard))
                 return true;
         return false;
     }
@@ -68,9 +68,10 @@ public:
       @return the container created under this key. If the container
                  was not created, null was returned.
      */
-    inline OInterfaceContainerHelper4<listener>* getContainer(const key& rKey) 
const
+    inline OInterfaceContainerHelper4<listener>* 
getContainer(std::unique_lock<std::mutex>& rGuard,
+                                                              const key& rKey) 
const
     {
-        auto iter = find(rKey);
+        auto iter = find(rGuard, rKey);
         if (iter != m_aMap.end())
             return (*iter).second.get();
         return nullptr;
@@ -94,7 +95,7 @@ public:
     inline sal_Int32 addInterface(::std::unique_lock<::std::mutex>& rGuard, 
const key& rKey,
                                   const css::uno::Reference<listener>& 
rListener)
     {
-        auto iter = find(rKey);
+        auto iter = find(rGuard, rKey);
         if (iter == m_aMap.end())
         {
             auto pLC = new OInterfaceContainerHelper4<listener>();
@@ -117,7 +118,7 @@ public:
                                      const css::uno::Reference<listener>& 
rListener)
     {
         // search container with id nUik
-        auto iter = find(rKey);
+        auto iter = find(rGuard, rKey);
         // container found?
         if (iter != m_aMap.end())
             return (*iter).second->removeInterface(rGuard, rListener);
@@ -158,7 +159,7 @@ public:
     /**
       Remove all elements of all containers. Does not delete the container.
      */
-    inline void clear()
+    inline void clear(std::unique_lock<std::mutex>& /*rGuard*/)
     {
         for (const auto& rPair : m_aMap)
             rPair.second->clear();
@@ -169,7 +170,8 @@ private:
     typedef ::std::vector<std::pair<key, 
std::unique_ptr<OInterfaceContainerHelper4<listener>>>>
         InterfaceMap;
     InterfaceMap m_aMap;
-    typename InterfaceMap::const_iterator find(const key& rKey) const
+    typename InterfaceMap::const_iterator find(std::unique_lock<std::mutex>& 
/*rGuard*/,
+                                               const key& rKey) const
     {
         auto iter = m_aMap.begin();
         auto end = m_aMap.end();
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index bcee2360e268..50b238d7a5d3 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -123,7 +123,7 @@ void SfxStatusDispatcher::ReleaseAll()
 void SfxStatusDispatcher::sendStatusChanged(const OUString& rURL, const 
css::frame::FeatureStateEvent& rEvent)
 {
     std::unique_lock aGuard(maMutex);
-    ::comphelper::OInterfaceContainerHelper4<css::frame::XStatusListener>* 
pContnr = maListeners.getContainer(rURL);
+    ::comphelper::OInterfaceContainerHelper4<css::frame::XStatusListener>* 
pContnr = maListeners.getContainer(aGuard, rURL);
     if (!pContnr)
         return;
     pContnr->forEach(aGuard,
diff --git a/ucbhelper/source/provider/resultset.cxx 
b/ucbhelper/source/provider/resultset.cxx
index 6318f5082d20..1615c72ade3c 100644
--- a/ucbhelper/source/provider/resultset.cxx
+++ b/ucbhelper/source/provider/resultset.cxx
@@ -1303,7 +1303,7 @@ void ResultSet::propertyChanged( const 
beans::PropertyChangeEvent& rEvt ) const
 
     // Notify listeners interested especially in the changed property.
     comphelper::OInterfaceContainerHelper4<beans::XPropertyChangeListener>* 
pPropsContainer
-        = m_pImpl->m_pPropertyChangeListeners->getContainer(
+        = m_pImpl->m_pPropertyChangeListeners->getContainer(aGuard,
                                                         rEvt.PropertyName );
     if ( pPropsContainer )
     {
@@ -1312,7 +1312,7 @@ void ResultSet::propertyChanged( const 
beans::PropertyChangeEvent& rEvt ) const
 
     // Notify listeners interested in all properties.
     pPropsContainer
-        = m_pImpl->m_pPropertyChangeListeners->getContainer( OUString() );
+        = m_pImpl->m_pPropertyChangeListeners->getContainer( aGuard, 
OUString() );
     if ( pPropsContainer )
     {
         comphelper::OInterfaceIteratorHelper4 aIter( aGuard, *pPropsContainer 
);

Reply via email to