commit f0e1d504dbf57f0c0041ae14f32a5a092a8a1afe Author: Arthur Edelstein arthuredelstein@gmail.com Date: Mon Mar 30 14:50:27 2015 -0700
Bug #15510: Detach event watchers when finished --- src/chrome/content/tor-circuit-display.js | 15 +++++++++++---- src/modules/tor-control-port.js | 10 +++++----- 2 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/src/chrome/content/tor-circuit-display.js b/src/chrome/content/tor-circuit-display.js index 917f1f0..4197944 100644 --- a/src/chrome/content/tor-circuit-display.js +++ b/src/chrome/content/tor-circuit-display.js @@ -129,7 +129,7 @@ let getCircuitStatusByID = function* (aController, circuitID) { // corresponding circuit. Whenever the first stream on a new circuit is seen, // looks up u+p and records the node data in the credentialsToNodeDataMap. let collectIsolationData = function (aController) { - aController.watchEvent( + return aController.watchEvent( "STREAM", streamEvent => streamEvent.StreamStatus === "SENTCONNECT", streamEvent => Task.spawn(function* () { @@ -313,10 +313,13 @@ let syncDisplayWithSelectedTab = (function() { // A reference to this function (called createTorCircuitDisplay) is exported as a global. let setupDisplay = function (host, port, password, enablePrefName) { let myController = null, + stopCollectingIsolationData = null, stop = function() { if (myController) { syncDisplayWithSelectedTab(false); - myController.close(); + if (stopCollectingIsolationData) { + stopCollectingIsolationData(); + } myController = null; } }, @@ -326,16 +329,20 @@ let setupDisplay = function (host, port, password, enablePrefName) { // An error has occurred. logger.eclog(5, err); logger.eclog(5, "Disabling tor display circuit because of an error."); + myController.close(); stop(); }); syncDisplayWithSelectedTab(true); - collectIsolationData(myController); + stopCollectingIsolationData = collectIsolationData(myController); } }; try { let unbindPref = bindPrefAndInit(enablePrefName, on => { if (on) start(); else stop(); }); // When this chrome window is unloaded, we need to unbind the pref. - window.addEventListener("unload", unbindPref); + window.addEventListener("unload", function () { + unbindPref(); + stop(); + }); } catch (e) { logger.eclog(5, "Error: " + e.message + "\n" + e.stack); } diff --git a/src/modules/tor-control-port.js b/src/modules/tor-control-port.js index 710643e..e4c7d16 100644 --- a/src/modules/tor-control-port.js +++ b/src/modules/tor-control-port.js @@ -606,9 +606,10 @@ event.messageToData = function (type, message) {
// __event.watchEvent(controlSocket, type, filter, onData)__. // Watches for a particular type of event. If filter(data) returns true, the event's -// data is pass to the onData callback. +// data is pass to the onData callback. Returns a zero arg function that +// stops watching the event. event.watchEvent = function (controlSocket, type, filter, onData) { - controlSocket.addNotificationCallback(new RegExp("^650." + type, "i"), + return controlSocket.addNotificationCallback(new RegExp("^650." + type, "i"), function (message) { let data = event.messageToData(type, message); if (filter === null || filter(data)) { @@ -635,9 +636,8 @@ tor.controller = function (host, port, password, onError) { return { getInfo : key => info.getInfo(socket, key), getInfoMultiple : keys => info.getInfoMultiple(socket, keys), getConf : key => info.getConf(socket, key), - watchEvent : function (type, filter, onData) { - event.watchEvent(socket, type, filter, onData); - }, + watchEvent : (type, filter, onData) => + event.watchEvent(socket, type, filter, onData), isOpen : () => isOpen, close : () => { isOpen = false; socket.close(); } };
tor-commits@lists.torproject.org