diff options
author | Caolán McNamara <caolanm@redhat.com> | 2023-04-06 12:17:10 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2023-04-06 16:46:10 +0200 |
commit | 5402e881ea057ac2956dbcf9942015627601da87 (patch) | |
tree | 6eed5f3985fffef597b8c208ad3922da42cffd11 /sw | |
parent | a6d5b89274b01b94d1802c5457cd9b71f84d9e37 (diff) |
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 <caolanm@redhat.com>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx | 18 | ||||
-rw-r--r-- | sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx | 5 |
2 files changed, 22 insertions, 1 deletions
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 |