Skip to content

Commit aaca599

Browse files
authored
Merge pull request #130 from notaz/release_lzma_init_buffers
release lzma init buffers
2 parents 9b6ff6c + 2099836 commit aaca599

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/libchdr_chd.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,28 @@ static void lzma_allocator_free(void* p )
459459
}
460460
}
461461

462+
/*-------------------------------------------------
463+
* lzma_allocator_free_unused
464+
* free unused buffers only
465+
*-------------------------------------------------
466+
*/
467+
468+
static void lzma_allocator_free_unused(lzma_allocator *codec)
469+
{
470+
int i;
471+
472+
for (i = 0; i < MAX_LZMA_ALLOCS; i++)
473+
{
474+
uint32_t *ptr = codec->allocptr[i];
475+
if (ptr && (*ptr & 1) == 0)
476+
{
477+
free(codec->allocptr[i]);
478+
codec->allocptr[i] = NULL;
479+
codec->allocptr2[i] = NULL;
480+
}
481+
}
482+
}
483+
462484
/*-------------------------------------------------
463485
* lzma_fast_alloc - fast malloc for lzma, which
464486
* allocates and frees memory frequently
@@ -600,6 +622,7 @@ static chd_error lzma_codec_init(void* codec, uint32_t hunkbytes)
600622
return CHDERR_DECOMPRESSION_ERROR;
601623
}
602624
LzmaEnc_Destroy(enc, (ISzAlloc*)alloc, (ISzAlloc*)alloc);
625+
lzma_allocator_free_unused(alloc);
603626

604627
/* do memory allocations */
605628
if (LzmaDec_Allocate(&lzma_codec->decoder, decoder_props, LZMA_PROPS_SIZE, (ISzAlloc*)alloc) != SZ_OK)

0 commit comments

Comments
 (0)