sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx | 18 ++++++++++++++++++ sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-)
New commits: commit 5402e881ea057ac2956dbcf9942015627601da87 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Thu Apr 6 12:17:10 2023 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Thu Apr 6 16:46:10 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/+/150098 Tested-by: Jenkins 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 313af767ba5d..71b0ad24fc58 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