Merge pull request #172 from poanetwork/possible-memory-leaks

(Fix) memory leaks: unreleased interval and events
This commit is contained in:
Victor Baranov 2018-10-31 19:13:14 +03:00 committed by GitHub
commit 9061ea4748
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 15 deletions

View File

@ -96,7 +96,9 @@ class BlacklistController {
*
*/
scheduleUpdates () {
if (this._phishingUpdateIntervalRef) return
if (this._phishingUpdateIntervalRef) {
clearInterval(this._phishingUpdateIntervalRef)
}
this.updatePhishingList().catch(log.warn)
this._phishingUpdateIntervalRef = setInterval(() => {
this.updatePhishingList().catch(log.warn)

View File

@ -109,15 +109,16 @@ class ExtensionPlatform {
})
}
_subscribeToNotificationClicked () {
if (!extension.notifications.onClicked.hasListener(this._viewOnEtherScan)) {
extension.notifications.onClicked.addListener(this._viewOnEtherScan)
_subscribeToNotificationClicked = () => {
if (!extension.notifications.onClicked.hasListener(this._viewOnExplorer)) {
extension.notifications.onClicked.addListener((url) => this._viewOnExplorer(url))
}
}
_viewOnEtherScan (txId) {
if (txId.startsWith('http://') || txId.startsWith('https://')) {
global.metamaskController.platform.openWindow({ url: txId })
_viewOnExplorer (url) {
if (url.startsWith('http://') || url.startsWith('https://')) {
extension.notifications.onClicked.removeListener(this._viewOnExplorer)
global.metamaskController.platform.openWindow({ url })
}
}

View File

@ -80,24 +80,24 @@ MenuDroppoComponent.prototype.componentDidMount = function () {
this.container = container
}
this.transitionStarted = this.transitionstartOccured.bind(this)
/*
* transitionstart event is not supported in Chrome yet. But it works for Firefox 53+.
* We need to handle this event only for FF because for Chrome we've hidden scrolls.
*/
this.refs.menuDroppoContainer.addEventListener('transitionstart', () => {
this.refs.menuDroppoContainer.style.overflow = 'hidden'
})
this.refs.menuDroppoContainer.addEventListener('transitionstart', this.transitionStarted)
this.refs.menuDroppoContainer.addEventListener('transitionend', () => {
if (!this.props.constOverflow) {
this.refs.menuDroppoContainer.style.overflow = 'auto'
}
})
this.transitionEnded = this.transitionendOccured.bind(this)
this.refs.menuDroppoContainer.addEventListener('transitionend', this.transitionEnded)
}
MenuDroppoComponent.prototype.componentWillUnmount = function () {
if (this && document.body) {
document.body.removeEventListener('click', this.globalClickHandler)
document.body.removeEventListener('transitionstart', this.transitionStarted)
document.body.removeEventListener('transitionend', this.transitionEnded)
}
}
@ -113,6 +113,16 @@ MenuDroppoComponent.prototype.globalClickOccurred = function (event) {
}
}
MenuDroppoComponent.prototype.transitionstartOccured = function (event) {
this.refs.menuDroppoContainer.style.overflow = 'hidden'
}
MenuDroppoComponent.prototype.transitionendOccured = function (event) {
if (!this.props.constOverflow) {
this.refs.menuDroppoContainer.style.overflow = 'auto'
}
}
function isDescendant (parent, child) {
var node = child.parentNode
while (node !== null) {