Skip to content

Commit

Permalink
Merge pull request #130 from notaz/release_lzma_init_buffers
Browse files Browse the repository at this point in the history
release lzma init buffers
  • Loading branch information
rtissera authored Sep 29, 2024
2 parents 9b6ff6c + 2099836 commit aaca599
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/libchdr_chd.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,28 @@ static void lzma_allocator_free(void* p )
}
}

/*-------------------------------------------------
* lzma_allocator_free_unused
* free unused buffers only
*-------------------------------------------------
*/

static void lzma_allocator_free_unused(lzma_allocator *codec)
{
int i;

for (i = 0; i < MAX_LZMA_ALLOCS; i++)
{
uint32_t *ptr = codec->allocptr[i];
if (ptr && (*ptr & 1) == 0)
{
free(codec->allocptr[i]);
codec->allocptr[i] = NULL;
codec->allocptr2[i] = NULL;
}
}
}

/*-------------------------------------------------
* lzma_fast_alloc - fast malloc for lzma, which
* allocates and frees memory frequently
Expand Down Expand Up @@ -600,6 +622,7 @@ static chd_error lzma_codec_init(void* codec, uint32_t hunkbytes)
return CHDERR_DECOMPRESSION_ERROR;
}
LzmaEnc_Destroy(enc, (ISzAlloc*)alloc, (ISzAlloc*)alloc);
lzma_allocator_free_unused(alloc);

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

0 comments on commit aaca599

Please sign in to comment.