diff options
author | Jia Tan <jiat0218@gmail.com> | 2023-05-13 19:36:09 +0800 |
---|---|---|
committer | Jia Tan <jiat0218@gmail.com> | 2023-07-17 23:34:55 +0800 |
commit | 072d29250113268536719ad0e040ab8a66fb6435 (patch) | |
tree | 06514c61c9dfb84a184c258c8bf046bee256f133 /src/xz | |
parent | xz: Separate string to filter conversion into a helper function. (diff) | |
download | xz-072d29250113268536719ad0e040ab8a66fb6435.tar.xz |
xz: Use lzma_filters_free() in forget_filter_chain().
This is a little cleaner than the previous implementation of
forget_filter_chain(). It is also more consistent since
lzma_str_to_filters() will always terminate the filter chain so there
is no need to terminate it later in coder_set_compression_settings().
Diffstat (limited to 'src/xz')
-rw-r--r-- | src/xz/coder.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/xz/coder.c b/src/xz/coder.c index 159b7d8b..df8a9778 100644 --- a/src/xz/coder.c +++ b/src/xz/coder.c @@ -84,10 +84,9 @@ forget_filter_chain(void) { // Setting a preset or using --filters makes us forget // the earlier custom filter chain (if any). - while (filters_count > 0) { - --filters_count; - free(filters[filters_count].options); - filters[filters_count].options = NULL; + if (filters_count > 0) { + lzma_filters_free(filters, NULL); + filters_count = 0; } string_to_filter_used = false; @@ -125,7 +124,9 @@ coder_add_filter(lzma_vli id, void *options) filters[filters_count].id = id; filters[filters_count].options = options; - ++filters_count; + // Terminate the filter chain with LZMA_VLI_UNKNOWN to simplify + // implementation of forget_filter_chain(). + filters[++filters_count].id = LZMA_VLI_UNKNOWN; // Setting a custom filter chain makes us forget the preset options. // This makes a difference if one specifies e.g. "xz -9 --lzma2 -e" @@ -234,11 +235,12 @@ coder_set_compression_settings(void) filters[0].id = opt_format == FORMAT_LZMA ? LZMA_FILTER_LZMA1 : LZMA_FILTER_LZMA2; filters[0].options = &opt_lzma; + filters_count = 1; - } - // Terminate the filter options array. - filters[filters_count].id = LZMA_VLI_UNKNOWN; + // Terminate the filter options array. + filters[1].id = LZMA_VLI_UNKNOWN; + } // If we are using the .lzma format, allow exactly one filter // which has to be LZMA1. |