framework/source/jobs/job.cxx |   25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

New commits:
commit ebbf4004d6061c3b31f9749bee06ef87afc5deb9
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Wed May 11 18:10:33 2022 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Thu May 12 10:57:58 2022 +0200

    framework: fix lock assert in Job::execute()
    
    include/osl/mutex.hxx:196: void osl::ClearableGuard<T>::clear() [with T = 
comphelper::SolarMutex]: Assertion `pT' failed.
    
    because clear() was called, then an exception was thrown and reset() was
    omitted.
    
    Change-Id: Iaa6d26e23261c2426eb3cc465b212752c4f454e5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134195
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/framework/source/jobs/job.cxx b/framework/source/jobs/job.cxx
index 39b867ac3291..d2d9403e4ab2 100644
--- a/framework/source/jobs/job.cxx
+++ b/framework/source/jobs/job.cxx
@@ -156,6 +156,18 @@ void Job::setJobData( const JobData& aData )
 void Job::execute( /*IN*/ const css::uno::Sequence< css::beans::NamedValue >& 
lDynamicArgs )
 {
     /* SAFE { */
+    class SolarMutexAntiGuard {
+        SolarMutexResettableGuard & m_rGuard;
+    public:
+        SolarMutexAntiGuard(SolarMutexResettableGuard & rGuard) : 
m_rGuard(rGuard)
+        {
+            m_rGuard.clear();
+        }
+        ~SolarMutexAntiGuard()
+        {
+            m_rGuard.reset();
+        }
+    };
     SolarMutexResettableGuard aWriteLock;
 
     // reject dangerous calls
@@ -191,23 +203,24 @@ void Job::execute( /*IN*/ const css::uno::Sequence< 
css::beans::NamedValue >& lD
         if (xAJob.is())
         {
             m_aAsyncWait.reset();
-            aWriteLock.clear();
+            SolarMutexAntiGuard const ag(aWriteLock);
             /* } SAFE */
             xAJob->executeAsync(lJobArgs, xThis);
             // wait for finishing this job - so this method
             // does the same for synchronous and asynchronous jobs!
             m_aAsyncWait.wait();
-            aWriteLock.reset();
             /* SAFE { */
             // Note: Result handling was already done inside the callback!
         }
         // execute it synchron
         else if (xSJob.is())
         {
-            aWriteLock.clear();
-            /* } SAFE */
-            css::uno::Any aResult = xSJob->execute(lJobArgs);
-            aWriteLock.reset();
+            css::uno::Any aResult;
+            {
+                SolarMutexAntiGuard const ag(aWriteLock);
+                /* } SAFE */
+                aResult = xSJob->execute(lJobArgs);
+            }
             /* SAFE { */
             impl_reactForJobResult(aResult);
         }

Reply via email to