From 3d3c9546a22463761e08ba14bb7a8dbe6a8aaa7f Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Fri, 14 Oct 2011 16:46:52 +0200 Subject: [PATCH] NetworkMenu: don't query DBus properties of removed objects Calling nm_access_point_get_ssid() in the handler of the access-point-removed signal can result in DBus request, which will then fail because the object was already removed at the server side. Instead, use a difference function to retrieve the access point object (the network), that compares directly by object identity. https://bugzilla.gnome.org/show_bug.cgi?id=651378 --- js/ui/status/network.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/js/ui/status/network.js b/js/ui/status/network.js index 4f368e3ca..966e8726c 100644 --- a/js/ui/status/network.js +++ b/js/ui/status/network.js @@ -1104,10 +1104,10 @@ NMDeviceWireless.prototype = { let activeAp = this.device.active_access_point; if (activeAp) { - let pos = this._findNetwork(activeAp); + let res = this._findExistingNetwork(activeAp); - if (pos != -1) - this._activeNetwork = this._networks[pos]; + if (res != null) + this._activeNetwork = this._networks[res.network]; } // we don't refresh the view here, setActiveConnection will @@ -1181,6 +1181,18 @@ NMDeviceWireless.prototype = { return true; }, + _findExistingNetwork: function(accessPoint) { + for (let i = 0; i < this._networks.length; i++) { + let apObj = this._networks[i]; + for (let j = 0; j < apObj.accessPoints.length; j++) { + if (apObj.accessPoints[j] == accessPoint) + return { network: i, ap: j }; + } + } + + return null; + }, + _findNetwork: function(accessPoint) { if (accessPoint.get_ssid() == null) return -1; @@ -1273,22 +1285,15 @@ NMDeviceWireless.prototype = { }, _accessPointRemoved: function(device, accessPoint) { - let pos = this._findNetwork(accessPoint); + let res = this._findExistingNetwork(accessPoint); - if (pos == -1) { + if (res == null) { log('Removing an access point that was never added'); return; } - let apObj = this._networks[pos]; - let i = apObj.accessPoints.indexOf(accessPoint); - - if (i == -1) { - log('Removing an access point that was never added'); - return; - } - - apObj.accessPoints.splice(i, 1); + let apObj = this._networks[res.network]; + apObj.accessPoints.splice(res.ap, 1); if (apObj.accessPoints.length == 0) { if (this._activeNetwork == apObj)