[Libreoffice-commits] core.git: UnoControls/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Thu Jul 22 16:51:28 UTC 2021


 UnoControls/source/controls/progressmonitor.cxx |   36 ++++++++++--------------
 1 file changed, 15 insertions(+), 21 deletions(-)

New commits:
commit 1296ded169adaa93d943eeb0273bf16835f7eb35
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu Jul 22 13:09:20 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu Jul 22 18:50:49 2021 +0200

    fix the mutex locking in impl_searchTopic
    
    you cannot take a pointer to something inside a guard and then use that
    data outside the guard.
    
    So remove the broken locking here, and make sure the call sites hold the
    lock.
    
    Change-Id: I37cc363ff937243d7965844e8bcda0018085c656
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119370
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/UnoControls/source/controls/progressmonitor.cxx b/UnoControls/source/controls/progressmonitor.cxx
index e8dca471b816..fa7ab1aa7098 100644
--- a/UnoControls/source/controls/progressmonitor.cxx
+++ b/UnoControls/source/controls/progressmonitor.cxx
@@ -192,6 +192,9 @@ void SAL_CALL ProgressMonitor::addText(
     sal_Bool bbeforeProgress
 )
 {
+    // Ready for multithreading
+    MutexGuard aGuard ( m_aMutex );
+
     // Safe impossible cases
     // Check valid call of this method.
     DBG_ASSERT ( impl_debug_checkParameter ( rTopic, rText ),                 "ProgressMonitor::addText()\nCall without valid parameters!\n");
@@ -210,9 +213,6 @@ void SAL_CALL ProgressMonitor::addText(
     aTextItem.sTopic   = rTopic;
     aTextItem.sText    = rText;
 
-    // Ready for multithreading
-    MutexGuard aGuard ( m_aMutex );
-
     // ... and insert it in right list.
     if ( bbeforeProgress )
     {
@@ -235,15 +235,15 @@ void SAL_CALL ProgressMonitor::removeText ( const OUString& rTopic, sal_Bool bbe
     // Check valid call of this method.
     DBG_ASSERT ( impl_debug_checkParameter ( rTopic ), "ProgressMonitor::removeText()\nCall without valid parameters!" );
 
+    // Ready for multithreading
+    MutexGuard aGuard ( m_aMutex );
+
     // Search the topic ...
     IMPL_TextlistItem* pSearchItem = impl_searchTopic ( rTopic, bbeforeProgress );
 
     if ( pSearchItem == nullptr )
         return;
 
-    // Ready for multithreading
-    MutexGuard aGuard ( m_aMutex );
-
     // ... delete item from right list ...
     if ( bbeforeProgress )
     {
@@ -278,14 +278,14 @@ void SAL_CALL ProgressMonitor::updateText (
     // Check valid call of this method.
     DBG_ASSERT ( impl_debug_checkParameter ( rTopic, rText ), "ProgressMonitor::updateText()\nCall without valid parameters!\n" );
 
+    // Ready for multithreading
+    MutexGuard aGuard ( m_aMutex );
+
     // Search topic ...
     IMPL_TextlistItem* pSearchItem = impl_searchTopic ( rTopic, bbeforeProgress );
 
     if ( pSearchItem != nullptr )
     {
-        // Ready for multithreading
-        MutexGuard aGuard ( m_aMutex );
-
         // ... update text ...
         pSearchItem->sText = rText;
 
@@ -791,20 +791,14 @@ IMPL_TextlistItem* ProgressMonitor::impl_searchTopic ( std::u16string_view rTopi
     // Get right textlist for following operations.
     ::std::vector< IMPL_TextlistItem >* pTextList;
 
-    // Ready for multithreading
+    if (bbeforeProgress)
     {
-        MutexGuard aGuard(m_aMutex);
-
-        if (bbeforeProgress)
-        {
-            pTextList = &maTextlist_Top;
-        }
-        else
-        {
-            pTextList = &maTextlist_Bottom;
-        }
+        pTextList = &maTextlist_Top;
+    }
+    else
+    {
+        pTextList = &maTextlist_Bottom;
     }
-    // Switch off guard.
 
     // Search the topic in textlist.
     size_t nPosition    = 0;


More information about the Libreoffice-commits mailing list