Blob Blame History Raw
From 3ee0b917f3f78d3a5a8bd1eeb99ff4adb975cf8c Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Wed, 20 Nov 2013 17:46:20 +0100
Subject: [PATCH] network: Fix crasher when NM restarts

Quite a few signals objects where signals were left connected
to singletons, and crashing when they triggered new signals.
---
 panels/network/net-device-ethernet.c |  9 +++++++--
 panels/network/net-device-ethernet.h |  1 +
 panels/network/net-device-wifi.c     | 20 ++++++++++++++++----
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/panels/network/net-device-ethernet.c b/panels/network/net-device-ethernet.c
index 8a9e35c..f2477d1 100644
--- a/panels/network/net-device-ethernet.c
+++ b/panels/network/net-device-ethernet.c
@@ -572,8 +572,8 @@ device_ethernet_constructed (GObject *object)
                           G_CALLBACK (add_profile), device);
 
         settings = net_object_get_remote_settings (NET_OBJECT (object));
-        g_signal_connect (settings, "connections-read",
-                          G_CALLBACK (remote_settings_read_cb), object);
+        device->remote_settings_id = g_signal_connect (settings, "connections-read",
+                                                       G_CALLBACK (remote_settings_read_cb), object);
 }
 
 static void
@@ -581,9 +581,14 @@ device_ethernet_finalize (GObject *object)
 {
         NetDeviceEthernet *device = NET_DEVICE_ETHERNET (object);
         GSList *connections, *l;
+        NMRemoteSettings *settings;
 
         g_object_unref (device->builder);
 
+        settings = net_object_get_remote_settings (NET_OBJECT (object));
+        g_signal_handler_disconnect (settings, device->remote_settings_id);
+        device->remote_settings_id = 0;
+
         connections = net_device_get_valid_connections (NET_DEVICE (device));
         for (l = connections; l; l = l->next) {
                 NMConnection *connection = l->data;
diff --git a/panels/network/net-device-ethernet.h b/panels/network/net-device-ethernet.h
index 84d0e43..e47f7dd 100644
--- a/panels/network/net-device-ethernet.h
+++ b/panels/network/net-device-ethernet.h
@@ -51,6 +51,7 @@ struct _NetDeviceEthernet
         GtkWidget *details_button;
         GtkWidget *add_profile_button;
         gboolean   updating_device;
+        guint      remote_settings_id;
 };
 
 struct _NetDeviceEthernetClass
diff --git a/panels/network/net-device-wifi.c b/panels/network/net-device-wifi.c
index 1ccc026..88582f1 100644
--- a/panels/network/net-device-wifi.c
+++ b/panels/network/net-device-wifi.c
@@ -65,6 +65,8 @@ struct _NetDeviceWifiPrivate
         gchar                   *selected_ssid_title;
         gchar                   *selected_connection_id;
         gchar                   *selected_ap_id;
+        guint                    wireless_status_id;
+        guint                    remote_settings_id;
 };
 
 G_DEFINE_TYPE (NetDeviceWifi, net_device_wifi, NET_TYPE_DEVICE)
@@ -1262,8 +1264,8 @@ net_device_wifi_constructed (GObject *object)
         G_OBJECT_CLASS (net_device_wifi_parent_class)->constructed (object);
 
         client = net_object_get_client (NET_OBJECT (device_wifi));
-        g_signal_connect (client, "notify::wireless-enabled",
-                          G_CALLBACK (wireless_enabled_toggled), device_wifi);
+        device_wifi->priv->wireless_status_id = g_signal_connect (client, "notify::wireless-enabled",
+                                                                  G_CALLBACK (wireless_enabled_toggled), device_wifi);
 
         nm_device = net_device_get_nm_device (NET_DEVICE (device_wifi));
 
@@ -1283,8 +1285,8 @@ net_device_wifi_constructed (GObject *object)
                 gtk_widget_set_sensitive (widget, TRUE);
 
         remote_settings = net_object_get_remote_settings (NET_OBJECT (device_wifi));
-        g_signal_connect (remote_settings, "connections-read",
-                          G_CALLBACK (remote_settings_read_cb), device_wifi);
+        device_wifi->priv->remote_settings_id = g_signal_connect (remote_settings, "connections-read",
+                                                                  G_CALLBACK (remote_settings_read_cb), device_wifi);
 
         widget = GTK_WIDGET (gtk_builder_get_object (device_wifi->priv->builder, "heading_list"));
         g_object_bind_property (device_wifi, "title", widget, "label", 0);
@@ -1297,6 +1299,16 @@ net_device_wifi_finalize (GObject *object)
 {
         NetDeviceWifi *device_wifi = NET_DEVICE_WIFI (object);
         NetDeviceWifiPrivate *priv = device_wifi->priv;
+        NMRemoteSettings *remote_settings;
+        NMClient *client;
+
+        client = net_object_get_client (NET_OBJECT (device_wifi));
+        g_signal_handler_disconnect (client, device_wifi->priv->wireless_status_id);
+        device_wifi->priv->wireless_status_id = 0;
+
+        remote_settings = net_object_get_remote_settings (NET_OBJECT (device_wifi));
+        g_signal_handler_disconnect (remote_settings, device_wifi->priv->remote_settings_id);
+        device_wifi->priv->remote_settings_id = 0;
 
         g_object_unref (priv->builder);
         g_free (priv->selected_ssid_title);
-- 
1.8.4.2