sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx |   18 ++++++++++++++++++
 sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx |    5 ++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

New commits:
commit 1915e355c63efa4ebce3bb12ca2ece3ce504934b
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Thu Apr 6 12:17:10 2023 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri Apr 21 10:55:51 2023 +0200

    tdf#154629 inspector sidebar panel use-after-free on switch to print preview
    
    Change-Id: I5489cd18213d82ae4174ca8d9d00f1da5aa1091d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150078
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150691
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx 
b/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx
index 1a3df50c27e8..2f9e305f1110 100644
--- a/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx
+++ b/sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx
@@ -70,6 +70,10 @@ 
WriterInspectorTextPanel::WriterInspectorTextPanel(weld::Widget* pParent)
     {
         m_oldLink = m_pShell->GetChgLnk();
         m_pShell->SetChgLnk(LINK(this, WriterInspectorTextPanel, 
AttrChangedNotify));
+
+        // tdf#154629 listen to know if the shell destructs before this panel 
does,
+        // which can happen on entering print preview
+        m_pShell->Add(this);
     }
 
     // Update panel on start
@@ -80,10 +84,24 @@ 
WriterInspectorTextPanel::WriterInspectorTextPanel(weld::Widget* pParent)
     updateEntries(aStore, m_nParIdx);
 }
 
+void WriterInspectorTextPanel::SwClientNotify(const SwModify& rModify, const 
SfxHint& rHint)
+{
+    if (rHint.GetId() == SfxHintId::SwLegacyModify)
+    {
+        const sw::LegacyModifyHint& rLegacy = static_cast<const 
sw::LegacyModifyHint&>(rHint);
+        if (rLegacy.GetWhich() == RES_OBJECTDYING)
+            m_pShell = nullptr;
+    }
+    SwClient::SwClientNotify(rModify, rHint);
+}
+
 WriterInspectorTextPanel::~WriterInspectorTextPanel()
 {
     if (m_pShell)
+    {
         m_pShell->SetChgLnk(m_oldLink);
+        m_pShell->Remove(this);
+    }
 }
 
 static OUString PropertyNametoRID(const OUString& rName)
diff --git a/sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx 
b/sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx
index fae619018851..2c2df34a9400 100644
--- a/sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx
+++ b/sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx
@@ -19,12 +19,13 @@
 #pragma once
 
 #include <svx/sidebar/InspectorTextPanel.hxx>
+#include <calbck.hxx>
 
 class SwWrtShell;
 
 namespace sw::sidebar
 {
-class WriterInspectorTextPanel final : public svx::sidebar::InspectorTextPanel
+class WriterInspectorTextPanel final : public 
svx::sidebar::InspectorTextPanel, public SwClient
 {
 public:
     static std::unique_ptr<PanelLayout> Create(weld::Widget* pParent);
@@ -40,6 +41,8 @@ private:
 
     // attributes have changed
     DECL_LINK(AttrChangedNotify, LinkParamNone*, void);
+
+    virtual void SwClientNotify(const SwModify&, const SfxHint& rHint) 
override;
 };
 
 } // end of namespace svx::sidebar

Reply via email to