From fa1fe4d7035d284ad10186a7b92fdc6929cabca3 Mon Sep 17 00:00:00 2001 From: Mark Callow Date: Wed, 21 Jun 2023 12:51:56 +0900 Subject: [PATCH] Fix memory leak of input_image in ktxTexture2_CompressAstcEx --- lib/astc_encode.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/astc_encode.cpp b/lib/astc_encode.cpp index 36fc1a5a90..657b518d12 100644 --- a/lib/astc_encode.cpp +++ b/lib/astc_encode.cpp @@ -688,21 +688,21 @@ ktxTexture2_CompressAstcEx(ktxTexture2* This, ktxAstcParams* params) { launchThreads(threadCount, compressionWorkloadRunner, &work); + buffer_out += levelImageSizeOut; + + // Reset ASTC context for next image + astcenc_compress_reset(astc_context); + offset += levelImageSizeIn; + + imageFree(input_image); + if (work.error != ASTCENC_SUCCESS) { std::cout << "ASTC compressor failed\n" << astcenc_get_error_string(work.error) << std::endl; - imageFree(input_image); - astcenc_context_free(astc_context); return KTX_INVALID_OPERATION; } - - buffer_out += levelImageSizeOut; - - // Reset ASTC context for next image - astcenc_compress_reset(astc_context); - offset += levelImageSizeIn; } }