Clean up notification handler on destruction to prevent shutdown crash

This commit is contained in:
Simon Stürz 2025-12-01 15:33:23 +01:00
parent 4cb037b518
commit 7eea6bd2c0

View File

@ -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();
}