From f3acf24c9af4005b074da7ea25052790bfbce332 Mon Sep 17 00:00:00 2001 From: Dirk Lemstra Date: Sat, 9 Dec 2023 21:53:10 +0100 Subject: [PATCH] Avoid duplicate free. --- src/pixels/pixel-collection.ts | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/pixels/pixel-collection.ts b/src/pixels/pixel-collection.ts index 4d1c675e..1ce32265 100644 --- a/src/pixels/pixel-collection.ts +++ b/src/pixels/pixel-collection.ts @@ -155,21 +155,12 @@ export class PixelCollection extends NativeInstance implements IPixelCollection toByteArray(x: number, y: number, width: number, height: number, mapping: string): Uint8Array | null { return this.use(x, y, width, height, mapping, instance => { - return PixelCollection.createArray(instance, width, height, mapping.length); - }); - } + if (instance === 0) + return null; - private static createArray(instance: number, width: number, height: number, channelCount: number): quantumArray | null { - if (instance === 0) - return null; - - try { - const count = width * height * channelCount; + const count = width * height * mapping.length; return ImageMagick._api.HEAPU8.slice(instance, instance + count); - } - finally { - instance = ImageMagick._api._MagickMemory_Relinquish(instance); - } + }); } private use(x: number, y: number, width: number, height: number, mapping: string, func: (instance: number) => TReturnType): TReturnType | null {