From 339705ef554d5ad7d646bb3e348e90a0a12713b7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 29 Nov 2025 01:10:03 +0000 Subject: [PATCH] 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. --- packages/webamp/js/skinParser.js | 11 ++++++++++- packages/webamp/js/skinParserUtils.ts | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/webamp/js/skinParser.js b/packages/webamp/js/skinParser.js index a5a6fa00..11b7900c 100644 --- a/packages/webamp/js/skinParser.js +++ b/packages/webamp/js/skinParser.js @@ -135,7 +135,16 @@ async function genGenTextSprites(zip) { sprites.forEach((sprite) => { letterWidths[sprite.name] = sprite.width; }); - return [letterWidths, SkinParserUtils.getSpriteUrisFromImg(img, sprites)]; + + const result = [letterWidths, SkinParserUtils.getSpriteUrisFromImg(img, sprites)]; + + // Clean up object URL if the image is an HTMLImageElement with a blob URL + // (ImageBitmap doesn't have a src property, so this only affects the fallback path) + if (img instanceof HTMLImageElement && img.src.startsWith("blob:")) { + URL.revokeObjectURL(img.src); + } + + return result; } // A promise that, given an array buffer returns a skin style object diff --git a/packages/webamp/js/skinParserUtils.ts b/packages/webamp/js/skinParserUtils.ts index cdda06b2..748cdfb7 100644 --- a/packages/webamp/js/skinParserUtils.ts +++ b/packages/webamp/js/skinParserUtils.ts @@ -224,7 +224,7 @@ export async function getGenExColors( // that with getColorAt, but I don't know a great way to make that type // safe. So, we'll just do this for now, where we explicitly call getColorAt // for each key. - return { + const colors = { // (1) x=48: item background (background to edits, listviews, etc.) itemBackground: getColorAt(48), // (2) x=50: item foreground (text colour of edits, listviews, etc.) @@ -270,4 +270,12 @@ export async function getGenExColors( // (22) x=90 List view background colour selected listTextSelectedBackground: getColorAt(90), }; + + // Clean up object URL if the image is an HTMLImageElement with a blob URL + // (ImageBitmap doesn't have a src property, so this only affects the fallback path) + if (img instanceof HTMLImageElement && img.src.startsWith("blob:")) { + URL.revokeObjectURL(img.src); + } + + return colors; }