Skip to content

Commit

Permalink
Avoid duplicate free.
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemstra committed Dec 9, 2023
1 parent cb058ec commit f3acf24
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/pixels/pixel-collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TReturnType>(x: number, y: number, width: number, height: number, mapping: string, func: (instance: number) => TReturnType): TReturnType | null {
Expand Down

0 comments on commit f3acf24

Please sign in to comment.