Merge pull request #5375 from Chemrat/master

disconnect GVolumeMonitor signals from GioLister before destroying it
This commit is contained in:
John Maguire 2016-05-24 14:40:24 +01:00
commit 75f9439843
4 changed files with 20 additions and 13 deletions

View File

@ -21,7 +21,7 @@
#include "core/logging.h" #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) { gpointer data, const int callback_param_count) {
guint signal_id = 0; guint signal_id = 0;
GQuark detail = 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, if (!g_signal_parse_name(signal, G_OBJECT_TYPE(source), &signal_id, &detail,
false)) { false)) {
qFatal("Connecting to invalid signal: %s", signal); qFatal("Connecting to invalid signal: %s", signal);
return false; return 0;
} }
GSignalQuery query; GSignalQuery query;
@ -39,9 +39,8 @@ bool CheckedGConnect(gpointer source, const char* signal, GCallback callback,
int signal_params = query.n_params + 2; int signal_params = query.n_params + 2;
if (signal_params != callback_param_count) { if (signal_params != callback_param_count) {
qFatal("Connecting callback to signal with different parameters counts"); qFatal("Connecting callback to signal with different parameters counts");
return false; return 0;
} }
g_signal_connect(source, signal, G_CALLBACK(callback), data); return g_signal_connect(source, signal, G_CALLBACK(callback), data);
return true;
} }

View File

@ -25,7 +25,7 @@
#include <boost/typeof/typeof.hpp> #include <boost/typeof/typeof.hpp>
// Do not call this directly, use CHECKED_GCONNECT instead. // Do not call this directly, use CHECKED_GCONNECT instead.
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); gpointer data, const int callback_param_count);
#define FUNCTION_ARITY(callback) \ #define FUNCTION_ARITY(callback) \
@ -33,6 +33,6 @@ bool CheckedGConnect(gpointer source, const char* signal, GCallback callback,
#define CHECKED_GCONNECT(source, signal, callback, data) \ #define CHECKED_GCONNECT(source, signal, callback, data) \
CheckedGConnect(source, signal, G_CALLBACK(callback), data, \ CheckedGConnect(source, signal, G_CALLBACK(callback), data, \
FUNCTION_ARITY(callback)); FUNCTION_ARITY(callback))
#endif // CORE_SIGNALCHECKER_H_ #endif // CORE_SIGNALCHECKER_H_

View File

@ -94,11 +94,17 @@ void GioLister::Init() {
g_list_free(mounts); g_list_free(mounts);
// Connect signals from the monitor // Connect signals from the monitor
CHECKED_GCONNECT(monitor_, "volume-added", &VolumeAddedCallback, this); signals_.append(CHECKED_GCONNECT(monitor_, "volume-added", &VolumeAddedCallback, this));
CHECKED_GCONNECT(monitor_, "volume-removed", &VolumeRemovedCallback, this); signals_.append(CHECKED_GCONNECT(monitor_, "volume-removed", &VolumeRemovedCallback, this));
CHECKED_GCONNECT(monitor_, "mount-added", &MountAddedCallback, this); signals_.append(CHECKED_GCONNECT(monitor_, "mount-added", &MountAddedCallback, this));
CHECKED_GCONNECT(monitor_, "mount-changed", &MountChangedCallback, this); signals_.append(CHECKED_GCONNECT(monitor_, "mount-changed", &MountChangedCallback, this));
CHECKED_GCONNECT(monitor_, "mount-removed", &MountRemovedCallback, this); signals_.append(CHECKED_GCONNECT(monitor_, "mount-removed", &MountRemovedCallback, this));
}
GioLister::~GioLister() {
for (gulong signal : signals_) {
g_signal_handler_disconnect(monitor_, signal);
}
} }
QStringList GioLister::DeviceUniqueIDs() { QStringList GioLister::DeviceUniqueIDs() {

View File

@ -36,6 +36,7 @@ class GioLister : public DeviceLister {
public: public:
GioLister() {} GioLister() {}
~GioLister();
int priority() const { return 50; } int priority() const { return 50; }
@ -137,6 +138,7 @@ class GioLister : public DeviceLister {
private: private:
ScopedGObject<GVolumeMonitor> monitor_; ScopedGObject<GVolumeMonitor> monitor_;
QList<gulong> signals_;
QMutex mutex_; QMutex mutex_;
QMap<QString, DeviceInfo> devices_; QMap<QString, DeviceInfo> devices_;