diff --git a/src/devices/wifi/nm-device-olpc-mesh.c b/src/devices/wifi/nm-device-olpc-mesh.c index e67d1a20a6..8dffeb4b39 100644 --- a/src/devices/wifi/nm-device-olpc-mesh.c +++ b/src/devices/wifi/nm-device-olpc-mesh.c @@ -77,6 +77,7 @@ enum { struct _NMDeviceOlpcMeshPrivate { NMDevice *companion; + NMManager *manager; gboolean stage1_waiting; }; @@ -397,7 +398,7 @@ find_companion (NMDeviceOlpcMesh *self) nm_device_add_pending_action (NM_DEVICE (self), "waiting for companion", TRUE); /* Try to find the companion if it's already known to the NMManager */ - for (list = nm_manager_get_devices (nm_manager_get ()); list ; list = g_slist_next (list)) { + for (list = nm_manager_get_devices (priv->manager); list ; list = g_slist_next (list)) { if (check_companion (self, NM_DEVICE (list->data))) { nm_device_queue_recheck_available (NM_DEVICE (self), NM_DEVICE_STATE_REASON_NONE, @@ -445,6 +446,7 @@ constructor (GType type, GObject *object; GObjectClass *klass; NMDeviceOlpcMesh *self; + NMDeviceOlpcMeshPrivate *priv; NMDeviceWifiCapabilities caps; klass = G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class); @@ -453,6 +455,7 @@ constructor (GType type, return NULL; self = NM_DEVICE_OLPC_MESH (object); + priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self); if (!nm_platform_wifi_get_capabilities (NM_PLATFORM_GET, nm_device_get_ifindex (NM_DEVICE (self)), &caps)) { _LOGW (LOGD_HW | LOGD_OLPC, "failed to initialize WiFi driver"); @@ -460,8 +463,10 @@ constructor (GType type, return NULL; } - g_signal_connect (nm_manager_get (), "device-added", G_CALLBACK (device_added_cb), self); - g_signal_connect (nm_manager_get (), "device-removed", G_CALLBACK (device_removed_cb), self); + priv->manager = g_object_ref (nm_manager_get ()); + + g_signal_connect (priv->manager, "device-added", G_CALLBACK (device_added_cb), self); + g_signal_connect (priv->manager, "device-removed", G_CALLBACK (device_removed_cb), self); /* shorter timeout for mesh connectivity */ nm_device_set_dhcp_timeout (NM_DEVICE (self), 20); @@ -506,10 +511,15 @@ static void dispose (GObject *object) { NMDeviceOlpcMesh *self = NM_DEVICE_OLPC_MESH (object); + NMDeviceOlpcMeshPrivate *priv = NM_DEVICE_OLPC_MESH_GET_PRIVATE (self); companion_cleanup (self); - g_signal_handlers_disconnect_by_func (nm_manager_get (), G_CALLBACK (device_added_cb), self); - g_signal_handlers_disconnect_by_func (nm_manager_get (), G_CALLBACK (device_removed_cb), self); + + if (priv->manager) { + g_signal_handlers_disconnect_by_func (priv->manager, G_CALLBACK (device_added_cb), self); + g_signal_handlers_disconnect_by_func (priv->manager, G_CALLBACK (device_removed_cb), self); + g_clear_object (&priv->manager); + } G_OBJECT_CLASS (nm_device_olpc_mesh_parent_class)->dispose (object); }