Skip to content

Commit 339705e

Browse files
committed
Clean up object URLs in genGenTextSprites and getGenExColors
Both functions load images from skin files and use them to extract data (letter sprites and colors). After extracting the data, the images are no longer needed. Clean up object URLs at this point to prevent leaks.
1 parent 668f106 commit 339705e

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

packages/webamp/js/skinParser.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,16 @@ async function genGenTextSprites(zip) {
135135
sprites.forEach((sprite) => {
136136
letterWidths[sprite.name] = sprite.width;
137137
});
138-
return [letterWidths, SkinParserUtils.getSpriteUrisFromImg(img, sprites)];
138+
139+
const result = [letterWidths, SkinParserUtils.getSpriteUrisFromImg(img, sprites)];
140+
141+
// Clean up object URL if the image is an HTMLImageElement with a blob URL
142+
// (ImageBitmap doesn't have a src property, so this only affects the fallback path)
143+
if (img instanceof HTMLImageElement && img.src.startsWith("blob:")) {
144+
URL.revokeObjectURL(img.src);
145+
}
146+
147+
return result;
139148
}
140149

141150
// A promise that, given an array buffer returns a skin style object

packages/webamp/js/skinParserUtils.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export async function getGenExColors(
224224
// that with getColorAt, but I don't know a great way to make that type
225225
// safe. So, we'll just do this for now, where we explicitly call getColorAt
226226
// for each key.
227-
return {
227+
const colors = {
228228
// (1) x=48: item background (background to edits, listviews, etc.)
229229
itemBackground: getColorAt(48),
230230
// (2) x=50: item foreground (text colour of edits, listviews, etc.)
@@ -270,4 +270,12 @@ export async function getGenExColors(
270270
// (22) x=90 List view background colour selected
271271
listTextSelectedBackground: getColorAt(90),
272272
};
273+
274+
// Clean up object URL if the image is an HTMLImageElement with a blob URL
275+
// (ImageBitmap doesn't have a src property, so this only affects the fallback path)
276+
if (img instanceof HTMLImageElement && img.src.startsWith("blob:")) {
277+
URL.revokeObjectURL(img.src);
278+
}
279+
280+
return colors;
273281
}

0 commit comments

Comments
 (0)