summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2023-04-06 12:17:10 +0100
committerXisco Fauli <xiscofauli@libreoffice.org>2023-04-21 10:55:51 +0200
commit1915e355c63efa4ebce3bb12ca2ece3ce504934b (patch)
tree076a2693f2e5f0502a442fd494618971f85e87e4
parentc2014929cf27e4b00e0ed18b9284a593bf8cf684 (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/+/150078 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org> Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150691 Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sw/source/uibase/sidebar/WriterInspectorTextPanel.cxx18
-rw-r--r--sw/source/uibase/sidebar/WriterInspectorTextPanel.hxx5
2 files changed, 22 insertions, 1 deletions
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