From be7e9249cf870d2eacb3881cc5c4d95611afe050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Mon, 5 Oct 2015 14:47:15 +0200 Subject: [PATCH] [globalaccel] Ensure we don't call into deleted InputRedirection on shutdown KGlobalAccel plugin gets deleted by a global static. At that point InputRedirection is already deleted but the plugin holds a static pointer to it. This change connects to the deleted signal by InputRedirection and ensures that the plugin doesn't call into the deleted code any more. --- plugins/kglobalaccel/kglobalaccel_plugin.cpp | 7 +++++++ plugins/kglobalaccel/kglobalaccel_plugin.h | 2 ++ 2 files changed, 9 insertions(+) diff --git a/plugins/kglobalaccel/kglobalaccel_plugin.cpp b/plugins/kglobalaccel/kglobalaccel_plugin.cpp index 7aa9c0ff7a..0466f6180e 100644 --- a/plugins/kglobalaccel/kglobalaccel_plugin.cpp +++ b/plugins/kglobalaccel/kglobalaccel_plugin.cpp @@ -38,9 +38,16 @@ bool KGlobalAccelImpl::grabKey(int key, bool grab) void KGlobalAccelImpl::setEnabled(bool enabled) { + if (m_shuttingDown) { + return; + } static KWin::InputRedirection *s_input = KWin::InputRedirection::self(); if (!s_input) { qFatal("This plugin is intended to be used with KWin and this is not KWin, exiting now"); + } else { + if (!m_inputDestroyedConnection) { + m_inputDestroyedConnection = connect(s_input, &QObject::destroyed, this, [this] { m_shuttingDown = true; }); + } } s_input->registerGlobalAccel(enabled ? this : nullptr); } diff --git a/plugins/kglobalaccel/kglobalaccel_plugin.h b/plugins/kglobalaccel/kglobalaccel_plugin.h index 7ecf2a8d99..4985a9076a 100644 --- a/plugins/kglobalaccel/kglobalaccel_plugin.h +++ b/plugins/kglobalaccel/kglobalaccel_plugin.h @@ -41,6 +41,8 @@ public Q_SLOTS: bool checkKeyPressed(int keyQt); private: + bool m_shuttingDown = false; + QMetaObject::Connection m_inputDestroyedConnection; }; #endif