From 7eea6bd2c0b6ad23088c7c729fc5eed44b401170 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Mon, 1 Dec 2025 15:33:23 +0100 Subject: [PATCH] Clean up notification handler on destruction to prevent shutdown crash --- libnymea-app/jsonrpc/jsonrpcclient.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libnymea-app/jsonrpc/jsonrpcclient.cpp b/libnymea-app/jsonrpc/jsonrpcclient.cpp index f106056a..76e15985 100644 --- a/libnymea-app/jsonrpc/jsonrpcclient.cpp +++ b/libnymea-app/jsonrpc/jsonrpcclient.cpp @@ -76,6 +76,17 @@ void JsonRpcClient::registerNotificationHandler(QObject *handler, const QString } m_notificationHandlers.insert(nameSpace, handler); m_notificationHandlerMethods.insert(handler, method); + + // Clean up if the handler gets destroyed so we don't dereference dangling pointers when + // processing notifications. + connect(handler, &QObject::destroyed, this, [this](QObject *obj){ + for (const QString &ns : m_notificationHandlers.keys(obj)) { + m_notificationHandlers.remove(ns, obj); + } + m_notificationHandlerMethods.remove(obj); + setNotificationsEnabled(); + }); + setNotificationsEnabled(); }