From 012cfbbc0ffc6e2f32321e6fe1b2492153339647 Mon Sep 17 00:00:00 2001 From: Jonathan Marten Date: Fri, 27 May 2022 11:45:30 +0100 Subject: [PATCH] Klipper: Avoid a crash on exit with the legacy application Caused by the context menu and the associated widget being set to the same object, leading to an access after destruction. Application: Klipper (klipper), signal: Segmentation fault Content of s_kcrashErrorMessage: std::unique_ptr = {get() = 0x0} #8 QObject::disconnect (member=0x0, ...) #9 KStatusNotifierItem::~KStatusNotifierItem () at knotifications/src/kstatusnotifieritem.cpp:71 #10 KlipperTray::~KlipperTray () at plasma-workspace/klipper/tray.h:13 --- klipper/tray.cpp | 12 ++++++++++++ klipper/tray.h | 1 + 2 files changed, 13 insertions(+) diff --git a/klipper/tray.cpp b/klipper/tray.cpp index 857e3a1e2..174d0d18b 100644 --- a/klipper/tray.cpp +++ b/klipper/tray.cpp @@ -34,6 +34,18 @@ KlipperTray::KlipperTray() slotSetToolTipFromHistory(); } +KlipperTray::~KlipperTray() +{ + // Klipper abuses the KStatusNotifierItem slightly by setting both + // the associated widget and the context menu to the same widget, + // the KlipperPopup. This is done so that either a left click or a + // right click on the icon brings up the combined menu. Unfortunately + // this causes a crash in ~KStatusNotifierItem() when it first + // deletes the menu and then tries to disconnect the associated widget. + // Work around this by resetting the associated widget first. + setAssociatedWidget(nullptr); +} + void KlipperTray::slotSetToolTipFromHistory() { const int TOOLTIP_LENGTH_LIMIT = 200; diff --git a/klipper/tray.h b/klipper/tray.h index bcc0777af..e17d97d4a 100644 --- a/klipper/tray.h +++ b/klipper/tray.h @@ -16,6 +16,7 @@ class KlipperTray : public KStatusNotifierItem public: KlipperTray(); + ~KlipperTray() override; public Q_SLOTS: void slotSetToolTipFromHistory();