From 132010ea4ebc84e90599f50fdd7550363ee44e1e Mon Sep 17 00:00:00 2001 From: Emmanuel Garcia Date: Wed, 2 Nov 2016 15:28:56 -0700 Subject: [PATCH] Fix #4123: Memory leak when using `importHref` --- src/standard/utils.html | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/standard/utils.html b/src/standard/utils.html index e574d1745c..8321952e90 100644 --- a/src/standard/utils.html +++ b/src/standard/utils.html @@ -375,20 +375,22 @@ var cached = list[link.href]; var imprt = cached || link; var self = this; + var loadListener = function(e) { + e.target.__firedLoad = true; + e.target.removeEventListener('load', loadListener); + e.target.removeEventListener('error', errorListener); + return onload.call(self, e); + }; + var errorListener = function(e) { + e.target.__firedError = true; + e.target.removeEventListener('load', loadListener); + e.target.removeEventListener('error', errorListener); + return onerror.call(self, e); + }; if (onload) { - var loadListener = function(e) { - e.target.__firedLoad = true; - e.target.removeEventListener('load', loadListener); - return onload.call(self, e); - } imprt.addEventListener('load', loadListener); } if (onerror) { - var errorListener = function(e) { - e.target.__firedError = true; - e.target.removeEventListener('error', errorListener); - return onerror.call(self, e); - } imprt.addEventListener('error', errorListener); } // if already loaded/erroed, fire 'fake' load/error event