sw/source/uibase/dochdl/swdtflvr.cxx |   15 ++++++++++-----
 sw/source/uibase/inc/swdtflvr.hxx    |    2 ++
 sw/source/uibase/inc/uivwimp.hxx     |    2 ++
 sw/source/uibase/uiview/uivwimp.cxx  |   13 +++++++++++++
 4 files changed, 27 insertions(+), 5 deletions(-)

New commits:
commit 445a0945e4d263c6bda37c58a7f6283ada5e2e36
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Thu Nov 16 17:13:37 2023 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Wed Nov 22 09:02:22 2023 +0100

    lok: disconnect clipboard leftovers in Writer to avoid crash
    
    When we closed one view which previously copied some larger selection
    in the Writer and other session after that modified content of that 
selection
    we got a crash. It was caused by old clipboard data still beeing used.
    On copy there is created SwTransferDdeLink which creates "Server" - 
SvLinkSource
    which is notified in SwTransferDdeLink::DataChanged when someone is
    editing
    previously copied selection. Let's disconnect that server on view close
    as it is no longer needed.
    
    some characteristic trace pieces for crash:
    
    libsofficeapp.so!LOKClipboard::setContents(LOKClipboard * this, const 
com::sun::star::uno::Reference<com::sun::star::datatransfer::XTransferable> & 
xTrans, const 
com::sun::star::uno::Reference<com::sun::star::datatransfer::clipboard::XClipboardOwner>
 & xClipboardOwner)
    ...
    libswlo.so!SwTransferable::RemoveDDELinkFormat(SwTransferable * this, 
vcl::Window & rWin)
    ...
    libsfxlo.so!sfx2::SvLinkSource::NotifyDataChanged(sfx2::SvLinkSource * this)
    ...
    libswlo.so!SwDataChanged::~SwDataChanged(SwDataChanged * this)
    
    Change-Id: I2ebab3db8bc42e20781874802563352ef263fdaa
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159563
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx 
b/sw/source/uibase/dochdl/swdtflvr.cxx
index 6c747df13c3f..3c0baabb3410 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -283,11 +283,7 @@ SwTransferable::~SwTransferable()
     SolarMutexGuard aSolarGuard;
 
     // the DDELink still needs the WrtShell!
-    if( m_xDdeLink.is() )
-    {
-        static_cast<SwTransferDdeLink*>( m_xDdeLink.get() )->Disconnect( true 
);
-        m_xDdeLink.clear();
-    }
+    DisconnectDDE();
 
     m_pWrtShell = nullptr;
 
@@ -393,6 +389,15 @@ void SwTransferable::RemoveDDELinkFormat(vcl::Window& rWin)
     CopyToClipboard(&rWin);
 }
 
+void SwTransferable::DisconnectDDE()
+{
+    if( m_xDdeLink.is() )
+    {
+        static_cast<SwTransferDdeLink*>( m_xDdeLink.get() )->Disconnect( true 
);
+        m_xDdeLink.clear();
+    }
+}
+
 namespace
 {
     //Resolves: fdo#40717 surely when we create a clipboard document we should
diff --git a/sw/source/uibase/inc/swdtflvr.hxx 
b/sw/source/uibase/inc/swdtflvr.hxx
index df16e3a8bd56..ac0579a3a9f0 100644
--- a/sw/source/uibase/inc/swdtflvr.hxx
+++ b/sw/source/uibase/inc/swdtflvr.hxx
@@ -185,6 +185,8 @@ public:
 
     // remove the DDE-Link format promise
     void RemoveDDELinkFormat(vcl::Window& rWin);
+    // disconnect to not receive DataChanged listener notifications
+    void DisconnectDDE();
 
     // paste - methods and helper methods for the paste
     static bool IsPaste( const SwWrtShell&, const TransferableDataHelper& );
diff --git a/sw/source/uibase/inc/uivwimp.hxx b/sw/source/uibase/inc/uivwimp.hxx
index 1cb5fd6590ed..3600ddc2258a 100644
--- a/sw/source/uibase/inc/uivwimp.hxx
+++ b/sw/source/uibase/inc/uivwimp.hxx
@@ -110,6 +110,8 @@ class SwView_Impl
     bool                        m_bSelectObject;
     bool                        m_bEditingPositionSet;
 
+    void                        DisconnectTransferableDDE();
+
 public:
     /// Redline author that's specific to this view.
     OUString m_sRedlineAuthor;
diff --git a/sw/source/uibase/uiview/uivwimp.cxx 
b/sw/source/uibase/uiview/uivwimp.cxx
index cea09ed3b5ba..7729c01c22f1 100644
--- a/sw/source/uibase/uiview/uivwimp.cxx
+++ b/sw/source/uibase/uiview/uivwimp.cxx
@@ -67,6 +67,7 @@ SwView_Impl::~SwView_Impl()
     view::XSelectionSupplier* pTextView = mxXTextView.get();
     static_cast<SwXTextView*>(pTextView)->Invalidate();
     mxXTextView.clear();
+
     if( mxScanEvtLstnr.is() )
            mxScanEvtLstnr->ViewDestroyed();
     if( mxClipEvtLstnr.is() )
@@ -74,6 +75,8 @@ SwView_Impl::~SwView_Impl()
         mxClipEvtLstnr->AddRemoveListener( false );
         mxClipEvtLstnr->ViewDestroyed();
     }
+    DisconnectTransferableDDE();
+
 #if HAVE_FEATURE_DBCONNECTIVITY && !ENABLE_FUZZERS
     m_xConfigItem.reset();
 #endif
@@ -218,6 +221,16 @@ void SwView_Impl::Invalidate()
     }
 }
 
+void SwView_Impl::DisconnectTransferableDDE()
+{
+    for (const auto& xTransferable: mxTransferables)
+    {
+        auto pTransferable = 
comphelper::getFromUnoTunnel<SwTransferable>(xTransferable.get());
+        if(pTransferable)
+            pTransferable->DisconnectDDE();
+    }
+}
+
 void SwView_Impl::AddTransferable(SwTransferable& rTransferable)
 {
     //prevent removing of the non-referenced SwTransferable

Reply via email to