Skip to content

Commit

Permalink
Fix inpage.js event handler memory leak (#6177)
Browse files Browse the repository at this point in the history
Fixes #6176
  • Loading branch information
gkaemmer authored and bitpshr committed Feb 18, 2019
1 parent b58a9bd commit 89c4353
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions app/scripts/inpage.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ console.warn('ATTENTION: In an effort to improve user privacy, MetaMask ' +
* @param {Function} handler - event handler
* @param {boolean} remove - removes this handler after being triggered
*/
function onMessage (messageType, handler, remove) {
window.addEventListener('message', function ({ data }) {
function onMessage (messageType, callback, remove) {
const handler = function ({ data }) {
if (!data || data.type !== messageType) { return }
remove && window.removeEventListener('message', handler)
handler.apply(window, arguments)
})
callback.apply(window, arguments)
}
window.addEventListener('message', handler)
}

//
Expand Down

0 comments on commit 89c4353

Please sign in to comment.