From 1296ded169adaa93d943eeb0273bf16835f7eb35 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 22 Jul 2021 13:09:20 +0200 Subject: 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 --- UnoControls/source/controls/progressmonitor.cxx | 36 +++++++++++-------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'UnoControls/source/controls/progressmonitor.cxx') 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; -- cgit