From d5e2b387fa8f6742fda141826e10def137176edd Mon Sep 17 00:00:00 2001 From: Jeroen van Rijn Date: Mon, 21 Jun 2021 22:47:54 +0200 Subject: [PATCH] PNG: Fix leak if you don't ask for metadata. --- core/image/png/helpers.odin | 6 ++---- core/image/png/png.odin | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/core/image/png/helpers.odin b/core/image/png/helpers.odin index 4c72643c2..4de6da947 100644 --- a/core/image/png/helpers.odin +++ b/core/image/png/helpers.odin @@ -34,10 +34,8 @@ destroy :: proc(img: ^Image) { } bytes.buffer_destroy(&img.pixels); - if img.metadata_ptr != nil && img.metadata_type == Info { - // Clean up Info. - free(img.metadata_ptr); - } + // Clean up Info. + free(img.metadata_ptr); /* We don't need to do anything for the individual chunks. diff --git a/core/image/png/png.odin b/core/image/png/png.odin index b4f25201f..4f3cd1bee 100644 --- a/core/image/png/png.odin +++ b/core/image/png/png.odin @@ -402,6 +402,8 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c } info := new(Info, context.allocator); + img.metadata_ptr = info; + img.metadata_type = typeid_of(Info); ctx := &compress.Context{ input = stream, @@ -663,10 +665,6 @@ load_from_stream :: proc(stream: io.Stream, options := Options{}, allocator := c } } - if .return_header in options || .return_metadata in options { - img.metadata_ptr = info; - img.metadata_type = typeid_of(Info); - } if .do_not_decompress_image in options { img.channels = final_image_channels; return img, nil;