From 9185809e791ea5b5740a3be0e93ac9a3fc1ef541 Mon Sep 17 00:00:00 2001 From: camilo tapia Date: Tue, 14 May 2013 00:00:18 +0200 Subject: [PATCH] Fixed a memory leak when adding too many event listeners to uncoughtexeption in the callbacks for QueuedItem --- lib/utils/QueueItem.js | 13 ++++++++++--- package.json | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/utils/QueueItem.js b/lib/utils/QueueItem.js index 12b7667c5c8..e0070574991 100644 --- a/lib/utils/QueueItem.js +++ b/lib/utils/QueueItem.js @@ -23,14 +23,21 @@ var QueueItem = module.exports = function(commandName, method, scope, args) { nextCallback = function(method, methodName) { return function(err,result) { - process.on('uncaughtException', function (exception) { + function errorCB() { self.next(); - }); + } + + process.on('uncaughtexception', errorCB); // call the callback method.call(scope, err, result); + // call the next item self.next(); + + // remove the listener to avoid memoryleakes. but do it after self.next so we know everything went well + process.removeListener('uncaughtexception', errorCB); + }; }; @@ -153,4 +160,4 @@ var QueueItem = module.exports = function(commandName, method, scope, args) { return child; }; -}; \ No newline at end of file +}; diff --git a/package.json b/package.json index 1c12d6eaee3..789b2ab44bd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "webdriverjs", "description": "A nodejs bindings implementation for selenium 2.0/webdriver", - "version": "0.7.2", + "version": "0.7.3", "homepage": "https://github.com/Camme/webdriverjs", "author": "camilo tapia ", "contributors": [