From 720b6cf38e8b9e15c23c26840694b7dea4a8e884 Mon Sep 17 00:00:00 2001 From: Mark Callow Date: Tue, 17 Aug 2021 18:07:35 +0900 Subject: [PATCH] Fix leak in zstd inflation. Fixes #465. --- lib/texture2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/texture2.c b/lib/texture2.c index 90a80003f5..308425940a 100644 --- a/lib/texture2.c +++ b/lib/texture2.c @@ -2289,7 +2289,7 @@ ktxTexture2_inflateZstdInt(ktxTexture2* This, ktx_uint8_t* pDeflatedData, ktxLevelIndexEntry* nindex; ktx_uint32_t uncompressedLevelAlignment; - ZSTD_DCtx* dctx = ZSTD_createDCtx(); + ZSTD_DCtx* dctx; if (pDeflatedData == NULL) return KTX_INVALID_VALUE; @@ -2308,6 +2308,7 @@ ktxTexture2_inflateZstdInt(ktxTexture2* This, ktx_uint8_t* pDeflatedData, ktxTexture2_calcPostInflationLevelAlignment(This); ktx_size_t inflatedByteLength = 0; + dctx = ZSTD_createDCtx(); for (int32_t level = This->numLevels - 1; level >= 0; level--) { size_t levelByteLength = ZSTD_decompressDCtx(dctx, pInflatedData + levelOffset, @@ -2339,6 +2340,7 @@ ktxTexture2_inflateZstdInt(ktxTexture2* This, ktx_uint8_t* pDeflatedData, This->dataSize = inflatedByteLength; This->supercompressionScheme = KTX_SS_NONE; memcpy(cindex, nindex, levelIndexByteLength); // Update level index + free(nindex); This->_private->_requiredLevelAlignment = uncompressedLevelAlignment; // Set bytesPlane as we're now sized. uint32_t* bdb = This->pDfd + 1;