Skip to content

Commit

Permalink
Merge pull request mozilla#734 from yxl/object-url-leak
Browse files Browse the repository at this point in the history
Revoke object URL to avoid ImagePlayer's leak. Fix mozilla#706.
  • Loading branch information
Marco committed Dec 17, 2014
2 parents 1c7dd00 + 4707ce6 commit bba2cf4
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion midp/media.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,9 @@ function ImagePlayer(playerContainer) {
}

ImagePlayer.prototype.realize = function() {
return new Promise((function(resolve, reject) {
var objectUrl;

var p = new Promise((function(resolve, reject) {
this.image.onload = resolve.bind(null, true);
this.image.onerror = function() {
reject(new JavaException("javax/microedition/media/MediaException", "Failed to load image"));
Expand All @@ -360,11 +362,23 @@ ImagePlayer.prototype.realize = function() {
var imgData = fs.read(fd);
fs.close(fd);
this.image.src = URL.createObjectURL(new Blob([ imgData ]));
objectUrl = this.image.src;
}).bind(this));
} else {
this.image.src = this.url;
}
}).bind(this));

var clean = function() {
if (!objectUrl) {
return;
}
URL.revokeObjectURL(objectUrl);
};

p.then(clean, clean);

return p;
}

ImagePlayer.prototype.start = function() {
Expand Down

0 comments on commit bba2cf4

Please sign in to comment.