Skip to content

Commit 01172b8

Browse files
CopilotBaseMax
andcommitted
Fix memory leaks, PNG quality parameter, and array bounds check
Co-authored-by: BaseMax <2658040+BaseMax@users.noreply.github.com>
1 parent 9acb6fd commit 01172b8

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

index.html

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -583,11 +583,18 @@ <h3>💡 Understanding the Results</h3>
583583
previewContainer.innerHTML = '';
584584
heatmapGrid.innerHTML = '';
585585
downloadButtons.innerHTML = '';
586-
Object.keys(convertedImages).forEach(key => delete convertedImages[key]);
586+
587+
// Revoke old blob URLs to prevent memory leaks
588+
Object.keys(convertedImages).forEach(key => {
589+
if (convertedImages[key].url) {
590+
URL.revokeObjectURL(convertedImages[key].url);
591+
}
592+
delete convertedImages[key];
593+
});
587594

588595
const quality = qualitySlider.value / 100;
589596
const formats = [
590-
{ name: 'PNG', mime: 'image/png', quality: 1 },
597+
{ name: 'PNG', mime: 'image/png', quality: undefined },
591598
{ name: 'JPEG', mime: 'image/jpeg', quality: quality },
592599
{ name: 'WebP', mime: 'image/webp', quality: quality }
593600
];
@@ -775,8 +782,9 @@ <h3>💡 Understanding the Results</h3>
775782
const convertedCtx = canvas.getContext('2d');
776783
const convertedData = convertedCtx.getImageData(0, 0, canvas.width, canvas.height);
777784

778-
// Calculate pixel differences
779-
for (let i = 0; i < originalImageData.data.length; i += 4) {
785+
// Calculate pixel differences (ensure same dimensions)
786+
const maxLength = Math.min(originalImageData.data.length, convertedData.data.length);
787+
for (let i = 0; i < maxLength; i += 4) {
780788
const rDiff = Math.abs(originalImageData.data[i] - convertedData.data[i]);
781789
const gDiff = Math.abs(originalImageData.data[i + 1] - convertedData.data[i + 1]);
782790
const bDiff = Math.abs(originalImageData.data[i + 2] - convertedData.data[i + 2]);

0 commit comments

Comments
 (0)