From 948140fab56f593e60b3f623bda5ba1c97f2d6ab Mon Sep 17 00:00:00 2001 From: Valeriy Date: Wed, 11 May 2016 17:58:12 +0300 Subject: [PATCH] disconnect GVolumeMonitor signals from GioLister before destroying it fixes #5369 --- src/core/signalchecker.cpp | 9 ++++----- src/core/signalchecker.h | 6 +++--- src/devices/giolister.cpp | 18 +++++++++++++----- src/devices/giolister.h | 2 ++ 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/core/signalchecker.cpp b/src/core/signalchecker.cpp index 20767f284..2b0505638 100644 --- a/src/core/signalchecker.cpp +++ b/src/core/signalchecker.cpp @@ -21,7 +21,7 @@ #include "core/logging.h" -bool CheckedGConnect(gpointer source, const char* signal, GCallback callback, +gulong CheckedGConnect(gpointer source, const char* signal, GCallback callback, gpointer data, const int callback_param_count) { guint signal_id = 0; GQuark detail = 0; @@ -29,7 +29,7 @@ bool CheckedGConnect(gpointer source, const char* signal, GCallback callback, if (!g_signal_parse_name(signal, G_OBJECT_TYPE(source), &signal_id, &detail, false)) { qFatal("Connecting to invalid signal: %s", signal); - return false; + return 0; } GSignalQuery query; @@ -39,9 +39,8 @@ bool CheckedGConnect(gpointer source, const char* signal, GCallback callback, int signal_params = query.n_params + 2; if (signal_params != callback_param_count) { qFatal("Connecting callback to signal with different parameters counts"); - return false; + return 0; } - g_signal_connect(source, signal, G_CALLBACK(callback), data); - return true; + return g_signal_connect(source, signal, G_CALLBACK(callback), data); } diff --git a/src/core/signalchecker.h b/src/core/signalchecker.h index 75977e6f5..79b6b5364 100644 --- a/src/core/signalchecker.h +++ b/src/core/signalchecker.h @@ -25,14 +25,14 @@ #include // Do not call this directly, use CHECKED_GCONNECT instead. -bool CheckedGConnect(gpointer source, const char* signal, GCallback callback, - gpointer data, const int callback_param_count); +gulong CheckedGConnect(gpointer source, const char* signal, GCallback callback, + gpointer data, const int callback_param_count); #define FUNCTION_ARITY(callback) \ boost::function_types::function_arity::value #define CHECKED_GCONNECT(source, signal, callback, data) \ CheckedGConnect(source, signal, G_CALLBACK(callback), data, \ - FUNCTION_ARITY(callback)); + FUNCTION_ARITY(callback)) #endif // CORE_SIGNALCHECKER_H_ diff --git a/src/devices/giolister.cpp b/src/devices/giolister.cpp index 1979f189c..d48cc4806 100644 --- a/src/devices/giolister.cpp +++ b/src/devices/giolister.cpp @@ -94,11 +94,19 @@ void GioLister::Init() { g_list_free(mounts); // Connect signals from the monitor - CHECKED_GCONNECT(monitor_, "volume-added", &VolumeAddedCallback, this); - CHECKED_GCONNECT(monitor_, "volume-removed", &VolumeRemovedCallback, this); - CHECKED_GCONNECT(monitor_, "mount-added", &MountAddedCallback, this); - CHECKED_GCONNECT(monitor_, "mount-changed", &MountChangedCallback, this); - CHECKED_GCONNECT(monitor_, "mount-removed", &MountRemovedCallback, this); + signals_.append(CHECKED_GCONNECT(monitor_, "volume-added", &VolumeAddedCallback, this)); + signals_.append(CHECKED_GCONNECT(monitor_, "volume-removed", &VolumeRemovedCallback, this)); + signals_.append(CHECKED_GCONNECT(monitor_, "mount-added", &MountAddedCallback, this)); + signals_.append(CHECKED_GCONNECT(monitor_, "mount-changed", &MountChangedCallback, this)); + signals_.append(CHECKED_GCONNECT(monitor_, "mount-removed", &MountRemovedCallback, this)); +} + +GioLister::~GioLister() +{ + foreach(gulong signal, signals_) + { + g_signal_handler_disconnect(monitor_, signal); + } } QStringList GioLister::DeviceUniqueIDs() { diff --git a/src/devices/giolister.h b/src/devices/giolister.h index eafa69dc6..c01680bb2 100644 --- a/src/devices/giolister.h +++ b/src/devices/giolister.h @@ -36,6 +36,7 @@ class GioLister : public DeviceLister { public: GioLister() {} + ~GioLister(); int priority() const { return 50; } @@ -137,6 +138,7 @@ class GioLister : public DeviceLister { private: ScopedGObject monitor_; + QList signals_; QMutex mutex_; QMap devices_;