Skip to content

Commit

Permalink
fix(heif): properly clean image resource
Browse files Browse the repository at this point in the history
Closes: #55
  • Loading branch information
gotson committed Aug 1, 2024
1 parent d2845ef commit a4f6f64
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public static void decode(final ImageInputStream stream, BasicInfo info, final W

MemorySegment heifContext = null;
MemorySegment handle = null;
MemorySegment image = null;
try {
heif_h.heif_init(arena, MemorySegment.NULL);
heifContext = heif_h.heif_context_alloc();
Expand All @@ -132,7 +133,7 @@ public static void decode(final ImageInputStream stream, BasicInfo info, final W
checkError(
heif_h.heif_decode_image(arena, handle, imagePtr, HeifColorSpace.HEIF_COLOR_SPACE_RGB.intValue(), HeifChroma.HEIF_CHROMA_INTERLEAVED_RGBA.intValue(),
MemorySegment.NULL));
var image = imagePtr.get(C_POINTER, 0);
image = imagePtr.get(C_POINTER, 0);

var stridePtr = arena.allocate(C_INT);
var pixels = heif_h.heif_image_get_plane_readonly(image, heif_channel_interleaved(), stridePtr);
Expand Down Expand Up @@ -163,6 +164,7 @@ public static void decode(final ImageInputStream stream, BasicInfo info, final W
raster.setDataElements(0, 0, raster.getWidth(), raster.getHeight(), pixelsRaster);
}
} finally {
if (image != null) heif_h.heif_image_release(image);
if (heifContext != null) heif_h.heif_context_free(heifContext);
if (handle != null) heif_h.heif_image_handle_release(handle);
heif_h.heif_deinit();
Expand Down

0 comments on commit a4f6f64

Please sign in to comment.