basctl/source/basicide/doceventnotifier.cxx |   28 +++++++++++++++++-----------
 sfx2/source/view/lokhelper.cxx              |    2 +-
 2 files changed, 18 insertions(+), 12 deletions(-)

New commits:
commit 883947f5c26f7b672954d0c051b171e70a74734b
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Mon Aug 21 09:49:02 2023 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Aug 23 09:28:27 2023 +0200

    tdf#156721 Crash if cursor in Basic IDE is in a macro from a document..
    
    .. and that document is closed
    
    regression from
        commit f3e127217d8daa443b8eda52ac4810e375cc7d63
        Author: Noel Grandin <noel.gran...@collabora.co.uk>
        Date:   Tue May 9 15:21:20 2023 +0200
    use comphelper::WeakComponentImplHelper in
    DocumentEventNotifier::Impl
    
    Change-Id: I5c8e68cd222ee1d66dc832700c4a39fd74223643
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155889
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    (cherry picked from commit ab38a8d13de0b14b3c389ef27152aac958033401)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155921
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/basctl/source/basicide/doceventnotifier.cxx 
b/basctl/source/basicide/doceventnotifier.cxx
index 81bb50be3919..254c719bb5cc 100644
--- a/basctl/source/basicide/doceventnotifier.cxx
+++ b/basctl/source/basicide/doceventnotifier.cxx
@@ -148,20 +148,26 @@ namespace basctl
             if ( !_rEvent.EventName.equalsAscii( aEvent.pEventName ) )
                 continue;
 
+            // Listener implementations require that we hold the mutex, but to 
avoid lock ordering issues,
+            // we need to take the solar mutex before we take our own mutex.
+            aGuard.unlock();
+
+            // Listener implements require that we hold the solar mutex.
+            SolarMutexGuard aSolarGuard;
+
+            // Take the lock again, so we can check our local fields.
+            aGuard.lock();
+            if ( impl_isDisposed_nothrow(aGuard) )
+                // somebody took the chance to dispose us -> bail out
+                return;
+            DocumentEventListener* pListener = m_pListener;
             ScriptDocument aDocument( xDocument );
-            {
-                // the listener implementations usually require the 
SolarMutex, so lock it here.
-                // But ensure the proper order of locking the solar and the 
own mutex
-                aGuard.unlock();
-                SolarMutexGuard aSolarGuard;
-                std::unique_lock aGuard2( m_aMutex );
+            // We cannot call the listener while holding our mutex because the 
listener
+            // call might trigger an event which call back into us.
+            aGuard.unlock();
 
-                if ( impl_isDisposed_nothrow(aGuard2) )
-                    // somebody took the chance to dispose us -> bail out
-                    return;
+            (pListener->*aEvent.listenerMethod)( aDocument );
 
-                (m_pListener->*aEvent.listenerMethod)( aDocument );
-            }
             break;
         }
     }
commit 59081e0fded0389d39269b86be346102fc31124e
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Thu Aug 17 08:24:05 2023 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Aug 23 09:28:20 2023 +0200

    sfx2: fix crash in SfxLokHelper::notifyOtherView()
    
    Crashreport signature:
    
    Fatal signal received: SIGSEGV code: 1 for address: 0x0
    program/libmergedlo.so
            SfxLokHelper::notifyOtherView(SfxViewShell const*, SfxViewShell 
const*, int, boost::property_tree::basic_ptree<std::string, std::string, 
std::less<std::string> > const&)
                    sfx2/source/view/lokhelper.cxx:473
    program/libmergedlo.so
            ImpEditView::ShowCursor(bool, bool)
                    editeng/source/editeng/impedit.cxx:1423
    program/../program/libsclo.so
            ScViewData::SetEditEngine(ScSplitPos, ScEditEngineDefaulter*, 
vcl::Window*, short, int)
                    sc/source/ui/view/viewdata.cxx:1635
    program/libsclo.so
            ScTabView::UpdateEditView()
                    sc/source/ui/view/tabview3.cxx:2190
    
    Change-Id: I219a1e9685db9bc3ea03d6ab67ff5db74aac9343
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155823
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    (cherry picked from commit 20f6e960cda073012a56597bf6544524240ce246)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/155920
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>

diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index d56862d26493..f5369161c94a 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -463,7 +463,7 @@ void SfxLokHelper::notifyOtherView(const SfxViewShell* 
pThisView, SfxViewShell c
                                    int nType, const 
boost::property_tree::ptree& rTree)
 {
     assert(pThisView != nullptr && "pThisView must be valid");
-    if (DisableCallbacks::disabled())
+    if (DisableCallbacks::disabled() || !pOtherView)
         return;
 
     const int viewId = SfxLokHelper::getView(pThisView);

Reply via email to