svx/inc/shapecollection.hxx                      |    4 ++--
 svx/source/accessibility/ChildrenManagerImpl.cxx |    6 ++++--
 svx/source/unodraw/unoshcol.cxx                  |   12 ++++++------
 3 files changed, 12 insertions(+), 10 deletions(-)

New commits:
commit adfbf35c0c102c7cead29845bde807947df4e30d
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Sun Dec 1 15:19:27 2024 +0000
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Mon Dec 2 17:41:26 2024 +0100

    cid#1606759 Data race condition
    
    Change-Id: I1357972c5ca8c6441533f15423134707efd36e33
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177684
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Jenkins

diff --git a/svx/inc/shapecollection.hxx b/svx/inc/shapecollection.hxx
index 44988281bb75..47eaec2e2e6d 100644
--- a/svx/inc/shapecollection.hxx
+++ b/svx/inc/shapecollection.hxx
@@ -31,7 +31,7 @@ class SvxShapeCollection final
                                       css::lang::XComponent>
 {
 private:
-    std::mutex m_aMutex;
+    mutable std::mutex m_aMutex;
     std::vector<css::uno::Reference<css::drawing::XShape>> maShapeContainer;
     comphelper::OInterfaceContainerHelper4<css::lang::XEventListener> 
maEventListeners;
     bool bDisposed = false;
@@ -67,7 +67,7 @@ public:
     virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) 
override;
     virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() 
override;
 
-    void getAllShapes(std::vector<css::uno::Reference<css::drawing::XShape>>& 
rShapes) const;
+    std::vector<css::uno::Reference<css::drawing::XShape>> getAllShapes() 
const;
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/accessibility/ChildrenManagerImpl.cxx 
b/svx/source/accessibility/ChildrenManagerImpl.cxx
index 70c9e4e37b2b..29b3f76bf891 100644
--- a/svx/source/accessibility/ChildrenManagerImpl.cxx
+++ b/svx/source/accessibility/ChildrenManagerImpl.cxx
@@ -871,17 +871,19 @@ void ChildrenManagerImpl::UpdateSelection()
         if (!xSelectedShape.is() && xSelectedShapeAccess.is())
         {
             sal_Int32 nCount = xSelectedShapeAccess->getCount();
-            aSortedSelectedShapes.reserve(nCount);
             if (auto pSvxShape = 
dynamic_cast<SvxShapeCollection*>(xSelectedShapeAccess.get()))
             {
-                pSvxShape->getAllShapes(aSortedSelectedShapes);
+                aSortedSelectedShapes = pSvxShape->getAllShapes();
             }
             else
+            {
+                aSortedSelectedShapes.reserve(nCount);
                 for (sal_Int32 i = 0; i < nCount; ++i)
                 {
                     css::uno::Reference<css::drawing::XShape> 
xShape(xSelectedShapeAccess->getByIndex(i), uno::UNO_QUERY);
                     aSortedSelectedShapes.push_back(xShape);
                 }
+            }
             std::sort(aSortedSelectedShapes.begin(), 
aSortedSelectedShapes.end());
         }
 
diff --git a/svx/source/unodraw/unoshcol.cxx b/svx/source/unodraw/unoshcol.cxx
index b99f6674a371..116247e1916b 100644
--- a/svx/source/unodraw/unoshcol.cxx
+++ b/svx/source/unodraw/unoshcol.cxx
@@ -147,7 +147,6 @@ sal_Int32 SAL_CALL SvxShapeCollection::getCount()
     return maShapeContainer.size();
 }
 
-
 uno::Any SAL_CALL SvxShapeCollection::getByIndex( sal_Int32 Index )
 {
     if( Index < 0 || Index >= getCount() )
@@ -158,6 +157,12 @@ uno::Any SAL_CALL SvxShapeCollection::getByIndex( 
sal_Int32 Index )
     return uno::Any( xShape );
 }
 
+std::vector<css::uno::Reference<css::drawing::XShape>> 
SvxShapeCollection::getAllShapes() const
+{
+    std::unique_lock g(m_aMutex);
+    return maShapeContainer;
+}
+
 // XElementAccess
 uno::Type SAL_CALL SvxShapeCollection::getElementType()
 {
@@ -185,11 +190,6 @@ uno::Sequence< OUString > SAL_CALL 
SvxShapeCollection::getSupportedServiceNames(
     return { u"com.sun.star.drawing.Shapes"_ustr, 
u"com.sun.star.drawing.ShapeCollection"_ustr };
 }
 
-void 
SvxShapeCollection::getAllShapes(std::vector<css::uno::Reference<css::drawing::XShape>>&
 rShapes) const
-{
-    rShapes = maShapeContainer;
-}
-
 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
 com_sun_star_drawing_SvxShapeCollection_get_implementation(
     css::uno::XComponentContext *,

Reply via email to