Commit 038b7e30 authored by Fushan Wen's avatar Fushan Wen 💬 Committed by Nate Graham
Browse files

kded/devicemonitor: Check BlueDevilDaemon exists when calling login1PrepareForSleep

It's possible that BlueDevilDaemon has been destroyed, but PrepareForSleep
is received before DeviceMonitor is destroyed, so a crash will happen. To prevent
the crash, add a check in login1PrepareForSleep to validate BlueDevilDaemon still exists.

BUG: 450195
FIXED-IN: 5.24.1


(cherry picked from commit fad0578a)
parent a105108a
Pipeline #137336 passed with stage
in 51 seconds
......@@ -23,6 +23,7 @@
DeviceMonitor::DeviceMonitor(BlueDevilDaemon *daemon)
: QObject(daemon)
, m_manager(daemon->manager())
, m_isParentValid(true)
, m_config(KSharedConfig::openConfig(QStringLiteral("bluedevilglobalrc")))
{
Q_FOREACH (BluezQt::AdapterPtr adapter, m_manager->adapters()) {
......@@ -39,6 +40,17 @@ DeviceMonitor::DeviceMonitor(BlueDevilDaemon *daemon)
// Catch suspend/resume events so we can save status when suspending and
// resume when waking up
// It's possible that BlueDevilDaemon has been destroyed, but PrepareForSleep is
// received before DeviceMonitor is destroyed, so a crash will happen. To prevent
// the crash, add a check in login1PrepareForSleep to validate BlueDevilDaemon still exists.
connect(
parent(),
&QObject::destroyed,
this,
[this] {
m_isParentValid = false;
},
Qt::DirectConnection);
QDBusConnection::systemBus().connect(QStringLiteral("org.freedesktop.login1"),
QStringLiteral("/org/freedesktop/login1"),
QStringLiteral("org.freedesktop.login1.Manager"),
......@@ -116,6 +128,10 @@ void DeviceMonitor::deviceConnectedChanged(bool connected)
void DeviceMonitor::login1PrepareForSleep(bool active)
{
if (!m_isParentValid) {
return;
}
if (active) {
qCDebug(BLUEDEVIL_KDED_LOG) << "About to suspend";
saveState();
......
......@@ -46,6 +46,7 @@ private:
KFilePlacesModel *places();
BluezQt::Manager *m_manager;
bool m_isParentValid;
KFilePlacesModel *m_places = nullptr;
KSharedConfig::Ptr m_config;
};
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment