From a35ff3c73766b1accf03a2d2c76b12ed5f721302 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Thu, 9 May 2024 14:39:41 +0800 Subject: [PATCH] Fix memory leak when ASTC compression fails --- modules/astcenc/image_compress_astcenc.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/astcenc/image_compress_astcenc.cpp b/modules/astcenc/image_compress_astcenc.cpp index 941c1f44be1a..499cf739c4a0 100644 --- a/modules/astcenc/image_compress_astcenc.cpp +++ b/modules/astcenc/image_compress_astcenc.cpp @@ -132,7 +132,10 @@ void _compress_astc(Image *r_img, Image::ASTCFormat p_format) { int dst_mip_w, dst_mip_h; int dst_ofs = Image::get_image_mipmap_offset_and_dimensions(width, height, target_format, i, dst_mip_w, dst_mip_h); // Ensure that mip offset is a multiple of 8 (etcpak expects uint64_t pointer). - ERR_FAIL_COND(dst_ofs % 8 != 0); + if (unlikely(dst_ofs % 8 != 0)) { + astcenc_context_free(context); + ERR_FAIL_MSG("astcenc: Mip offset is not a multiple of 8."); + } uint8_t *dest_mip_write = (uint8_t *)&dest_write[dst_ofs]; // Compress image.