@@ -459,6 +459,28 @@ static void lzma_allocator_free(void* p )
459
459
}
460
460
}
461
461
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
+
462
484
/*-------------------------------------------------
463
485
* lzma_fast_alloc - fast malloc for lzma, which
464
486
* allocates and frees memory frequently
@@ -600,6 +622,7 @@ static chd_error lzma_codec_init(void* codec, uint32_t hunkbytes)
600
622
return CHDERR_DECOMPRESSION_ERROR ;
601
623
}
602
624
LzmaEnc_Destroy (enc , (ISzAlloc * )alloc , (ISzAlloc * )alloc );
625
+ lzma_allocator_free_unused (alloc );
603
626
604
627
/* do memory allocations */
605
628
if (LzmaDec_Allocate (& lzma_codec -> decoder , decoder_props , LZMA_PROPS_SIZE , (ISzAlloc * )alloc ) != SZ_OK )
0 commit comments