summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Redondo <[email protected]>2025-04-09 16:06:40 +0200
committerDavid Redondo <[email protected]>2025-04-10 00:55:58 +0200
commit677ee0cf7cf492482b4dd4d96986b93f89cb69b3 (patch)
treee1b38647fccc5cb1e58cf340e5197e1c9f858518
parentab7eb492cba64fe985ea80b2f0be22c1c18f3c5e (diff)
QGnomeTheme: Prevent leak of QDBusPendingCallWatcher
Otherwise the watcher can outlive the theme and the connected lambda calls into the already destroyed theme. Change-Id: I55e7834d1eb806d9f5f1945a4e1016d14b2969b6 Reviewed-by: Axel Spoerl <[email protected]>
-rw-r--r--src/gui/platform/unix/qgnometheme.cpp5
-rw-r--r--src/gui/platform/unix/qgnometheme_p.h2
2 files changed, 4 insertions, 3 deletions
diff --git a/src/gui/platform/unix/qgnometheme.cpp b/src/gui/platform/unix/qgnometheme.cpp
index c70c3580185..aafaff3732b 100644
--- a/src/gui/platform/unix/qgnometheme.cpp
+++ b/src/gui/platform/unix/qgnometheme.cpp
@@ -66,15 +66,14 @@ QGnomeThemePrivate::QGnomeThemePrivate()
message.setArguments({});
message << appearanceNamespace << contrastKey;
- QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(dbus.asyncCall(message));
- QObject::connect(watcher, &QDBusPendingCallWatcher::finished, watcher, [this](QDBusPendingCallWatcher *watcher) {
+ pendingCallWatcher = std::make_unique<QDBusPendingCallWatcher>(dbus.asyncCall(message));
+ QObject::connect(pendingCallWatcher.get(), &QDBusPendingCallWatcher::finished, pendingCallWatcher.get(), [this](QDBusPendingCallWatcher *watcher) {
if (!watcher->isError()) {
QDBusPendingReply<QVariant> reply = *watcher;
if (Q_LIKELY(reply.isValid()))
updateHighContrast(static_cast<Qt::ContrastPreference>(reply.value().toUInt()));
}
initDbus();
- watcher->deleteLater();
});
} else {
qCWarning(lcQpaThemeGnome) << "dbus connection failed. Last error: " << dbus.lastError();
diff --git a/src/gui/platform/unix/qgnometheme_p.h b/src/gui/platform/unix/qgnometheme_p.h
index 08bba609875..41df765eccf 100644
--- a/src/gui/platform/unix/qgnometheme_p.h
+++ b/src/gui/platform/unix/qgnometheme_p.h
@@ -24,6 +24,7 @@ QT_BEGIN_NAMESPACE
class QGnomeThemePrivate;
#if QT_CONFIG(dbus)
class QDBusListener;
+class QDBusPendingCallWatcher;
#endif
class Q_GUI_EXPORT QGnomeTheme : public QGenericUnixTheme
@@ -66,6 +67,7 @@ public:
Qt::ContrastPreference m_contrast = Qt::ContrastPreference::NoPreference;
private:
std::unique_ptr<QDBusListener> dbus;
+ std::unique_ptr<QDBusPendingCallWatcher> pendingCallWatcher;
bool initDbus();
void updateColorScheme(const QString &themeName);
void updateHighContrast(Qt::ContrastPreference contrast);