embeddedobj/source/inc/oleembobj.hxx      |    3 ++-
 embeddedobj/source/msole/olecomponent.cxx |    2 +-
 embeddedobj/source/msole/olepersist.cxx   |    9 +++++----
 3 files changed, 8 insertions(+), 6 deletions(-)

New commits:
commit d782606d235fbd7991a1e6dc24f4cbe9a09ca735
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri Oct 18 12:41:07 2024 +0500
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Fri Oct 18 14:34:39 2024 +0500

    Avoid deadlock
    
    As seen in the following call stacks:
    
    Main thread
    
      sal3!osl_acquireMutex+0x49 [libre-office-git-repo\sal\osl\w32\mutex.cxx @ 
65]
      emboleobj!osl::Mutex::acquire+0x9 
[libre-office-git-repo\include\osl\mutex.hxx @ 63]
      emboleobj!osl::ClearableGuard<osl::Mutex>::{ctor}+0xd 
[libre-office-git-repo\include\osl\mutex.hxx @ 182]
      emboleobj!osl::ResettableGuard<osl::Mutex>::{ctor}+0xd 
[libre-office-git-repo\include\osl\mutex.hxx @ 236]
      emboleobj!OleEmbeddedObject::getStatus+0x72 
[libre-office-git-repombeddedobj\source\msole\oleembed.cxx @ 1133]
      sfxlo!SfxViewShell::CheckIPClient_Impl+0x42 
[libre-office-git-repo\sfx2\sourceiewiewsh.cxx @ 3563]
      sfxlo!SfxInPlaceClient_Impl::TimerHdl+0x40 
[libre-office-git-repo\sfx2\sourceiew\ipclient.cxx @ 628]
      sfxlo!SfxInPlaceClient_Impl::LinkStubTimerHdl+0x53 
[libre-office-git-repo\sfx2\sourceiew\ipclient.cxx @ 624]
      vcllo!Scheduler::CallbackTaskScheduling+0x130e [libre-office-git-repo
cl\sourcepp\scheduler.cxx @ 511]
      vclplug_winlo!WinSalTimer::ImplHandleElapsedTimer+0x2e 
[libre-office-git-repocl\winpp\saltimer.cxx @ 167]
      vclplug_winlo!ImplSalYield+0x14f [libre-office-git-repo
cl\winpp\salinst.cxx @ 525]
      vclplug_winlo!WinSalInstance::DoYield+0xad [libre-office-git-repo
cl\winpp\salinst.cxx @ 581]
      vcllo!ImplYield+0x367 [libre-office-git-repocl\sourcepp\svapp.cxx @ 393]
      vcllo!Application::Execute+0xfa [libre-office-git-repo
cl\sourcepp\svapp.cxx @ 369]
      sofficeapp!desktop::Desktop::Main+0x173f 
[libre-office-git-repo\desktop\sourcepppp.cxx @ 1605]
      vcllo!ImplSVMain+0xda [libre-office-git-repocl\sourcepp\svmain.cxx @ 
229]
      sofficeapp!soffice_main+0xf3 
[libre-office-git-repo\desktop\sourcepp\sofficemain.cxx @ 94]
    
    Request thread
    
      sal3!osl_acquireMutex+0x49 [libre-office-git-repo\sal\osl\w32\mutex.cxx @ 
65]
      vclplug_winlo!osl::Mutex::acquire+0xa 
[libre-office-git-repo\include\osl\mutex.hxx @ 63]
      vclplug_winlo!SalYieldMutex::doAcquire+0x91 [libre-office-git-repo
cl\winpp\salinst.cxx @ 148]
      emboleobj!SolarMutexReleaser::{dtor}+0xc [libre-office-git-repo\include
cl\svapp.hxx @ 1425]
      emboleobj!OleComponent::StoreOwnTmpIfNecessary+0x1d3 
[libre-office-git-repombeddedobj\source\msole\olecomponent.cxx @ 1365]
      emboleobj!OleEmbeddedObject::StoreObjectToStream+0x2f 
[libre-office-git-repombeddedobj\source\msole\olepersist.cxx @ 1032]
      emboleobj!OleEmbeddedObject::StoreToLocation_Impl+0x3cc 
[libre-office-git-repombeddedobj\source\msole\olepersist.cxx @ 1169]
      emboleobj!OleEmbeddedObject::storeAsEntry+0x152 
[libre-office-git-repombeddedobj\source\msole\olepersist.cxx @ 1523]
      comphelper!comphelper::EmbeddedObjectContainer::StoreEmbeddedObject+0x490 
[libre-office-git-repo      
comphelper!comphelper::EmbeddedObjectContainer::InsertEmbeddedObject+0x6f 
[libre-office-git-repo      
comphelper!comphelper::EmbeddedObjectContainer::RemoveEmbeddedObject+0x388 
[libre-office-git-repo      
comphelper!comphelper::EmbeddedObjectContainer::RemoveEmbeddedObject+0x46 
[libre-office-git-repo      swlo!SwOLENode::SavePersistentData+0x20b 
[libre-office-git-repo\sw\source      swlo!SwNodes::ChgNode+0x411 
[libre-office-git-repo\sw\source      swlo!SwNodes::MoveNodes+0x18e6 
[libre-office-git-repo\sw\source      
swlo!SwUndoSaveContent::MoveToUndoNds+0x1c1 [libre-office-git-repo\sw\source    
  swlo!SwUndoSaveSection::SaveSection+0x559 [libre-office-git-repo\sw\source    
  swlo!SwUndoSaveSection::SaveSection+0x55 [libre-office-git-repo\sw\source     
 swlo!SwUndoFlyBase::DelFly+0x127 [libre-office-git-repo\sw\source      
swlo!SwUndoDelLayFormat::SwUndoDelLayFormat+0x64 [libre-o
 ffice-git-repo\sw\source      swlo!std::make_unique+0x22 [C:\Program Files 
(x86)\Microsoft Visual Studio�9\BuildTools\VC\Tools\MSVC
.29.30133\include\memory @ 3382]
      swlo!sw::DocumentLayoutManager::DelLayoutFormat+0x283 
[libre-office-git-repo\sw\source      swlo!SwTextNode::DestroyAttr+0x82 
[libre-office-git-repo\sw\source      swlo!SwTextNode::EraseText+0x18f 
[libre-office-git-repo\sw\source      swlo!SwTextNode::DeleteAttributes+0x115 
[libre-office-git-repo\sw\source      swlo!SwXFrame::dispose+0xdb 
[libre-office-git-repo\sw\source      mscx_uno!`anonymous 
namespace'::cpp_call+0x710 [libre-office-git-reporidges\source      
mscx_uno!unoInterfaceProxyDispatch+0x2fa [libre-office-git-reporidges\source   
   binaryurplo!binaryurp::IncomingRequest::execute_throw+0x635 
[libre-office-git-repoinaryurp\source\incomingrequest.cxx @ 239]
      binaryurplo!binaryurp::IncomingRequest::execute+0xbf 
[libre-office-git-repoinaryurp\source\incomingrequest.cxx @ 79]
      binaryurplo!request+0x1c [libre-office-git-repoinaryurp\source eader.cxx 
@ 84]
      cppu3!cppu_threadpool::JobQueue::enter+0x21e [libre-office-git-repo      
cppu3!cppu_threadpool::ORequestThread::run+0xa0 [libre-office-git-repo    
    where the call to OleComponent::StoreOwnTmpIfNecessary from
    OleEmbeddedObject::StoreObjectToStream was made with m_aMutex
    held; and that mutex was attempted to be locked from the main
    thread, holding solar mutex.
    
    Change-Id: I1914188728cdaa9cdf22d216ec71f733d7780692
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175117
    Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com>
    Tested-by: Jenkins

diff --git a/embeddedobj/source/inc/oleembobj.hxx 
b/embeddedobj/source/inc/oleembobj.hxx
index d1eda24fe302..5f54a6706892 100644
--- a/embeddedobj/source/inc/oleembobj.hxx
+++ b/embeddedobj/source/inc/oleembobj.hxx
@@ -253,7 +253,8 @@ protected:
                             osl::ResettableMutexGuard& rGuard);
 #ifdef _WIN32
     /// @throws css::uno::Exception
-    void StoreObjectToStream( css::uno::Reference< css::io::XOutputStream > 
const & xOutStream );
+    void StoreObjectToStream(css::uno::Reference<css::io::XOutputStream> 
const& xOutStream,
+                             osl::ResettableMutexGuard& rGuard);
 #endif
     /// @throws css::uno::Exception
     void InsertVisualCache_Impl(
diff --git a/embeddedobj/source/msole/olecomponent.cxx 
b/embeddedobj/source/msole/olecomponent.cxx
index 4ccd7aa3a9e2..fb262c323cbd 100644
--- a/embeddedobj/source/msole/olecomponent.cxx
+++ b/embeddedobj/source/msole/olecomponent.cxx
@@ -1626,7 +1626,7 @@ uno::Any SAL_CALL OleComponent::getTransferData( const 
datatransfer::DataFlavor&
         if ( !m_pUnoOleObject )
             throw uno::RuntimeException();
 
-        m_pUnoOleObject->StoreObjectToStream( xTempOutStream );
+        m_pUnoOleObject->StoreObjectToStream(xTempOutStream, aGuard);
 
         xTempOutStream->closeOutput();
         xTempOutStream.clear();
diff --git a/embeddedobj/source/msole/olepersist.cxx 
b/embeddedobj/source/msole/olepersist.cxx
index 25649707118c..5d7818443b9d 100644
--- a/embeddedobj/source/msole/olepersist.cxx
+++ b/embeddedobj/source/msole/olepersist.cxx
@@ -1022,11 +1022,12 @@ uno::Reference< io::XOutputStream > 
OleEmbeddedObject::GetStreamForSaving()
 }
 
 
-void OleEmbeddedObject::StoreObjectToStream( uno::Reference< io::XOutputStream 
> const & xOutStream )
+void OleEmbeddedObject::StoreObjectToStream(uno::Reference<io::XOutputStream> 
const& xOutStream,
+                                            osl::ResettableMutexGuard& rGuard)
 {
     // this method should be used only on windows
     if ( m_pOleComponent )
-        m_pOleComponent->StoreOwnTmpIfNecessary();
+        ExecUnlocked([this] { m_pOleComponent->StoreOwnTmpIfNecessary(); }, 
rGuard);
 
     // now all the changes should be in temporary location
     if ( m_aTempURL.isEmpty() )
@@ -1165,7 +1166,7 @@ void OleEmbeddedObject::StoreToLocation_Impl(
         if ( !xOutStream.is() )
             throw io::IOException(); //TODO: access denied
 
-        StoreObjectToStream( xOutStream );
+        StoreObjectToStream(xOutStream, rGuard);
         bVisReplIsStored = true;
 
         if ( bSaveAs )
@@ -1736,7 +1737,7 @@ void SAL_CALL OleEmbeddedObject::storeOwn()
             throw io::IOException(); //TODO: access denied
 
         // TODO: does this work for links too?
-        StoreObjectToStream( GetStreamForSaving() );
+        StoreObjectToStream(GetStreamForSaving(), aGuard);
 
         // the replacement is changed probably, and it must be in the object 
stream
         if ( !m_pOleComponent->IsWorkaroundActive() )

Reply via email to