mirror of https://git.tukaani.org/xz.git
liblzma: Use lzma_filters_free() in more places.
This commit is contained in:
parent
90caaded2d
commit
e782af9110
|
@ -14,22 +14,6 @@
|
||||||
#include "check.h"
|
#include "check.h"
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
free_properties(lzma_block *block, const lzma_allocator *allocator)
|
|
||||||
{
|
|
||||||
// Free allocated filter options. The last array member is not
|
|
||||||
// touched after the initialization in the beginning of
|
|
||||||
// lzma_block_header_decode(), so we don't need to touch that here.
|
|
||||||
for (size_t i = 0; i < LZMA_FILTERS_MAX; ++i) {
|
|
||||||
lzma_free(block->filters[i].options, allocator);
|
|
||||||
block->filters[i].id = LZMA_VLI_UNKNOWN;
|
|
||||||
block->filters[i].options = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
extern LZMA_API(lzma_ret)
|
extern LZMA_API(lzma_ret)
|
||||||
lzma_block_header_decode(lzma_block *block,
|
lzma_block_header_decode(lzma_block *block,
|
||||||
const lzma_allocator *allocator, const uint8_t *in)
|
const lzma_allocator *allocator, const uint8_t *in)
|
||||||
|
@ -107,7 +91,7 @@ lzma_block_header_decode(lzma_block *block,
|
||||||
&block->filters[i], allocator,
|
&block->filters[i], allocator,
|
||||||
in, &in_pos, in_size);
|
in, &in_pos, in_size);
|
||||||
if (ret != LZMA_OK) {
|
if (ret != LZMA_OK) {
|
||||||
free_properties(block, allocator);
|
lzma_filters_free(block->filters, allocator);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -115,7 +99,7 @@ lzma_block_header_decode(lzma_block *block,
|
||||||
// Padding
|
// Padding
|
||||||
while (in_pos < in_size) {
|
while (in_pos < in_size) {
|
||||||
if (in[in_pos++] != 0x00) {
|
if (in[in_pos++] != 0x00) {
|
||||||
free_properties(block, allocator);
|
lzma_filters_free(block->filters, allocator);
|
||||||
|
|
||||||
// Possibly some new field present so use
|
// Possibly some new field present so use
|
||||||
// LZMA_OPTIONS_ERROR instead of LZMA_DATA_ERROR.
|
// LZMA_OPTIONS_ERROR instead of LZMA_DATA_ERROR.
|
||||||
|
|
|
@ -243,9 +243,7 @@ stream_decode(void *coder_ptr, const lzma_allocator *allocator,
|
||||||
|
|
||||||
// Free the allocated filter options since they are needed
|
// Free the allocated filter options since they are needed
|
||||||
// only to initialize the Block decoder.
|
// only to initialize the Block decoder.
|
||||||
for (size_t i = 0; i < LZMA_FILTERS_MAX; ++i)
|
lzma_filters_free(filters, allocator);
|
||||||
lzma_free(filters[i].options, allocator);
|
|
||||||
|
|
||||||
coder->block_options.filters = NULL;
|
coder->block_options.filters = NULL;
|
||||||
|
|
||||||
// Check if memory usage calculation and Block decoder
|
// Check if memory usage calculation and Block decoder
|
||||||
|
|
|
@ -929,18 +929,6 @@ decode_block_header(struct lzma_stream_coder *coder,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
cleanup_filters(lzma_filter *filters, const lzma_allocator *allocator)
|
|
||||||
{
|
|
||||||
for (uint32_t i = 0; i < LZMA_FILTERS_MAX; ++i) {
|
|
||||||
lzma_free(filters[i].options, allocator);
|
|
||||||
filters[i].options = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Get the size of the Compressed Data + Block Padding + Check.
|
/// Get the size of the Compressed Data + Block Padding + Check.
|
||||||
static size_t
|
static size_t
|
||||||
comp_blk_size(const struct lzma_stream_coder *coder)
|
comp_blk_size(const struct lzma_stream_coder *coder)
|
||||||
|
@ -1481,7 +1469,7 @@ stream_decode_mt(void *coder_ptr, const lzma_allocator *allocator,
|
||||||
|
|
||||||
// Free the allocated filter options since they are needed
|
// Free the allocated filter options since they are needed
|
||||||
// only to initialize the Block decoder.
|
// only to initialize the Block decoder.
|
||||||
cleanup_filters(coder->filters, allocator);
|
lzma_filters_free(coder->filters, allocator);
|
||||||
coder->thr->block_options.filters = NULL;
|
coder->thr->block_options.filters = NULL;
|
||||||
|
|
||||||
// Check if memory usage calculation and Block encoder
|
// Check if memory usage calculation and Block encoder
|
||||||
|
@ -1613,7 +1601,7 @@ stream_decode_mt(void *coder_ptr, const lzma_allocator *allocator,
|
||||||
|
|
||||||
// Free the allocated filter options since they are needed
|
// Free the allocated filter options since they are needed
|
||||||
// only to initialize the Block decoder.
|
// only to initialize the Block decoder.
|
||||||
cleanup_filters(coder->filters, allocator);
|
lzma_filters_free(coder->filters, allocator);
|
||||||
coder->block_options.filters = NULL;
|
coder->block_options.filters = NULL;
|
||||||
|
|
||||||
// Check if Block decoder initialization succeeded.
|
// Check if Block decoder initialization succeeded.
|
||||||
|
@ -1812,7 +1800,7 @@ stream_decoder_mt_end(void *coder_ptr, const lzma_allocator *allocator)
|
||||||
lzma_outq_end(&coder->outq, allocator);
|
lzma_outq_end(&coder->outq, allocator);
|
||||||
|
|
||||||
lzma_next_end(&coder->block_decoder, allocator);
|
lzma_next_end(&coder->block_decoder, allocator);
|
||||||
cleanup_filters(coder->filters, allocator);
|
lzma_filters_free(coder->filters, allocator);
|
||||||
lzma_index_hash_end(coder->index_hash, allocator);
|
lzma_index_hash_end(coder->index_hash, allocator);
|
||||||
|
|
||||||
lzma_free(coder, allocator);
|
lzma_free(coder, allocator);
|
||||||
|
@ -1939,7 +1927,7 @@ stream_decoder_mt_init(lzma_next_coder *next, const lzma_allocator *allocator,
|
||||||
next->memconfig = &stream_decoder_mt_memconfig;
|
next->memconfig = &stream_decoder_mt_memconfig;
|
||||||
next->get_progress = &stream_decoder_mt_get_progress;
|
next->get_progress = &stream_decoder_mt_get_progress;
|
||||||
|
|
||||||
memzero(coder->filters, sizeof(coder->filters));
|
coder->filters[0].id = LZMA_VLI_UNKNOWN;
|
||||||
memzero(&coder->outq, sizeof(coder->outq));
|
memzero(&coder->outq, sizeof(coder->outq));
|
||||||
|
|
||||||
coder->block_decoder = LZMA_NEXT_CODER_INIT;
|
coder->block_decoder = LZMA_NEXT_CODER_INIT;
|
||||||
|
@ -1953,7 +1941,7 @@ stream_decoder_mt_init(lzma_next_coder *next, const lzma_allocator *allocator,
|
||||||
|
|
||||||
// Cleanup old filter chain if one remains after unfinished decoding
|
// Cleanup old filter chain if one remains after unfinished decoding
|
||||||
// of a previous Stream.
|
// of a previous Stream.
|
||||||
cleanup_filters(coder->filters, allocator);
|
lzma_filters_free(coder->filters, allocator);
|
||||||
|
|
||||||
// By allocating threads from scratch we can start memory-usage
|
// By allocating threads from scratch we can start memory-usage
|
||||||
// accounting from scratch, too. Changes in filter and block sizes may
|
// accounting from scratch, too. Changes in filter and block sizes may
|
||||||
|
|
Loading…
Reference in New Issue