From ee568d5f5a3d04f32969fd2ba3113b9eeb175d63 Mon Sep 17 00:00:00 2001 From: Connor Christie Date: Sun, 9 Sep 2018 19:33:09 -0500 Subject: [PATCH] Upgrade obs-store and fix memory leaks --- app/scripts/metamask-controller.js | 10 +++++++--- package-lock.json | 8 ++++---- package.json | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 98cb62bfa..1060f508a 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -177,7 +177,7 @@ module.exports = class MetamaskController extends EventEmitter { blockTracker: this.blockTracker, getGasPrice: this.getGasPrice.bind(this), }) - this.txController.on('newUnapprovedTx', opts.showUnapprovedTx.bind(opts)) + this.txController.on('newUnapprovedTx', () => opts.showUnapprovedTx()) this.txController.on(`tx:status-update`, (txId, status) => { if (status === 'confirmed' || status === 'failed') { @@ -1229,8 +1229,10 @@ module.exports = class MetamaskController extends EventEmitter { ) dnode.on('remote', (remote) => { // push updates to popup - const sendUpdate = remote.sendUpdate.bind(remote) + const sendUpdate = (update) => remote.sendUpdate(update) this.on('update', sendUpdate) + // remove update listener once the connection ends + dnode.on('end', () => this.removeListener('update', sendUpdate)) }) } @@ -1280,10 +1282,12 @@ module.exports = class MetamaskController extends EventEmitter { * @param {*} outStream - The stream to provide public config over. */ setupPublicConfig (outStream) { + const configStream = asStream(this.publicConfigStore) pump( - asStream(this.publicConfigStore), + configStream, outStream, (err) => { + configStream.destroy() if (err) log.error(err) } ) diff --git a/package-lock.json b/package-lock.json index 016e25647..7b4de5e8c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21822,9 +21822,9 @@ } }, "obs-store": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/obs-store/-/obs-store-3.0.0.tgz", - "integrity": "sha512-ZHK0fwDZEecEvdiqQGnxrEshbqibVgsq4aIIe/5PIT8fGGprTTuGw1RXLMy5G1VN/KtnmEP6+n+aLH7BYuYCVA==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/obs-store/-/obs-store-3.0.2.tgz", + "integrity": "sha512-GzBr7KM2TYWoJSlF3sVo1cMIOeyxgXpEdegXLZyYONRpunFHsBdKwOba0ki17kN2stLaEwTNolJChGHafqM7Fw==", "requires": { "babel-preset-es2015": "^6.22.0", "babelify": "^7.3.0", @@ -21835,7 +21835,7 @@ "dependencies": { "babelify": { "version": "7.3.0", - "resolved": "https://registry.npmjs.org/babelify/-/babelify-7.3.0.tgz", + "resolved": "http://registry.npmjs.org/babelify/-/babelify-7.3.0.tgz", "integrity": "sha1-qlau3nBn/XvVSWZu4W3ChQh+iOU=", "requires": { "babel-core": "^6.0.14", diff --git a/package.json b/package.json index 0ef2ab6a9..13349bf6f 100644 --- a/package.json +++ b/package.json @@ -169,7 +169,7 @@ "multiplex": "^6.7.0", "number-to-bn": "^1.7.0", "obj-multiplex": "^1.0.0", - "obs-store": "^3.0.0", + "obs-store": "^3.0.2", "percentile": "^1.2.0", "pify": "^3.0.0", "ping-pong-stream": "^1.0.0",