crashreporting: crash in thesaurus dialog PostUserEvent

not reproducible, but a common error to post an event that
outlives the owner

Change-Id: Ic2633c504d853116d03e3322f552ae66e7e7e14e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141869
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
This commit is contained in:
Caolán McNamara
2022-10-26 10:34:32 +01:00
parent ad2310fec9
commit bef36eed84
2 changed files with 14 additions and 3 deletions

View File

@ -165,8 +165,8 @@ void SvxThesaurusDialog::LookUp_Impl()
m_xAlternativesCT->set_visible(m_bWordFound);
m_xNotFound->set_visible(!m_bWordFound);
if (m_bWordFound)
Application::PostUserEvent(LINK(this, SvxThesaurusDialog, SelectFirstHdl_Impl));
if (m_bWordFound && !m_nSelectFirstEvent)
m_nSelectFirstEvent = Application::PostUserEvent(LINK(this, SvxThesaurusDialog, SelectFirstHdl_Impl));
if (m_xWordCB->find_text(aText) == -1)
m_xWordCB->append_text(aText);
@ -217,13 +217,15 @@ IMPL_LINK( SvxThesaurusDialog, AlternativesDoubleClickHdl_Impl, weld::TreeView&,
//! workaround to set the selection since calling SelectEntryPos within
//! the double click handler does not work
Application::PostUserEvent(LINK(this, SvxThesaurusDialog, SelectFirstHdl_Impl));
if (!m_nSelectFirstEvent)
m_nSelectFirstEvent = Application::PostUserEvent(LINK(this, SvxThesaurusDialog, SelectFirstHdl_Impl));
return true;
}
IMPL_LINK_NOARG(SvxThesaurusDialog, SelectFirstHdl_Impl, void *, void)
{
m_nSelectFirstEvent = nullptr;
if (m_xAlternativesCT->n_children() >= 2)
{
m_xAlternativesCT->select(1); // pos 0 is a 'header' that is not selectable
@ -249,6 +251,7 @@ SvxThesaurusDialog::SvxThesaurusDialog(
, m_xReplaceEdit(m_xBuilder->weld_entry("replaceed"))
, m_xLangLB(m_xBuilder->weld_combo_box("langcb"))
, m_xReplaceBtn(m_xBuilder->weld_button("ok"))
, m_nSelectFirstEvent(nullptr)
{
m_aModifyIdle.SetInvokeHandler( LINK( this, SvxThesaurusDialog, ModifyTimer_Hdl ) );
m_aModifyIdle.SetPriority( TaskPriority::LOWEST );
@ -316,6 +319,11 @@ SvxThesaurusDialog::SvxThesaurusDialog(
SvxThesaurusDialog::~SvxThesaurusDialog()
{
if (m_nSelectFirstEvent)
{
Application::RemoveUserEvent(m_nSelectFirstEvent);
m_nSelectFirstEvent = nullptr;
}
}
IMPL_LINK_NOARG(SvxThesaurusDialog, ReplaceBtnHdl_Impl, weld::Button&, void)

View File

@ -26,6 +26,8 @@
#include <memory>
#include <stack>
struct ImplSVEvent;
class SvxThesaurusDialog : public SfxDialogController
{
Idle m_aModifyIdle;
@ -43,6 +45,7 @@ class SvxThesaurusDialog : public SfxDialogController
std::unique_ptr<weld::Entry> m_xReplaceEdit;
std::unique_ptr<weld::ComboBox> m_xLangLB;
std::unique_ptr<weld::Button> m_xReplaceBtn;
ImplSVEvent* m_nSelectFirstEvent;
public:
virtual ~SvxThesaurusDialog() override;