From bfea26d3e3d12de6ce9bbc01ad24a42d846021e5 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 6 Sep 2016 18:56:26 -0700 Subject: [PATCH 1/2] Ensure listener is cleaned up Also fixed bug when validating a tx with no value. --- app/scripts/background.js | 1 + app/scripts/lib/listener-manager.js | 25 +++++++++++++++++++++++++ app/scripts/metamask-controller.js | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 app/scripts/lib/listener-manager.js diff --git a/app/scripts/background.js b/app/scripts/background.js index 21a5eea65..18aaed7bf 100644 --- a/app/scripts/background.js +++ b/app/scripts/background.js @@ -86,6 +86,7 @@ function setupControllerConnection (stream) { stream.pipe(dnode).pipe(stream) dnode.on('remote', (remote) => { // push updates to popup + controller.ethStore.removeListener('update', controller.sendUpdate.bind(controller)) controller.ethStore.on('update', controller.sendUpdate.bind(controller)) controller.listeners.push(remote) idStore.on('update', controller.sendUpdate.bind(controller)) diff --git a/app/scripts/lib/listener-manager.js b/app/scripts/lib/listener-manager.js new file mode 100644 index 000000000..9e3c71afc --- /dev/null +++ b/app/scripts/lib/listener-manager.js @@ -0,0 +1,25 @@ +module.exports = class ListenerManager { + + constructor() { + this.cleaners = {} + } + + setup (name) { + if (!(name in this.cleaners)) { + this.cleaners[name] = [] + } + } + + addCleanup (name, cleaner) { + this.setup(name) + } + + cleanupOldListeners (name) { + this.setup(name) + this.cleaners[name].forEach((cleaner) => { + cleaner() + }) + this.cleaners[name] = [] + } + +} diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 83827ec76..5373cf0d9 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -220,7 +220,7 @@ module.exports = class MetamaskController { } enforceTxValidations (txParams) { - if (txParams.value.indexOf('-') === 0) { + if (('value' in txParams) && txParams.value.indexOf('-') === 0) { const msg = `Invalid transaction value of ${txParams.value} not a positive number.` return new Error(msg) } From 2564c0c51c39e428540e38b80558e45ec44357a8 Mon Sep 17 00:00:00 2001 From: Dan Finlay Date: Tue, 6 Sep 2016 18:57:18 -0700 Subject: [PATCH 2/2] Bump changelog --- CHANGELOG.md | 1 + app/scripts/lib/listener-manager.js | 25 ------------------------- 2 files changed, 1 insertion(+), 25 deletions(-) delete mode 100644 app/scripts/lib/listener-manager.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 9021fdf01..bea356ab6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - On fresh install, open a new tab with the MetaMask Introduction video. - Block negative values from transactions. +- Fixed a memory leak. ## 2.10.2 2016-09-02 diff --git a/app/scripts/lib/listener-manager.js b/app/scripts/lib/listener-manager.js deleted file mode 100644 index 9e3c71afc..000000000 --- a/app/scripts/lib/listener-manager.js +++ /dev/null @@ -1,25 +0,0 @@ -module.exports = class ListenerManager { - - constructor() { - this.cleaners = {} - } - - setup (name) { - if (!(name in this.cleaners)) { - this.cleaners[name] = [] - } - } - - addCleanup (name, cleaner) { - this.setup(name) - } - - cleanupOldListeners (name) { - this.setup(name) - this.cleaners[name].forEach((cleaner) => { - cleaner() - }) - this.cleaners[name] = [] - } - -}