]> git.ipfire.org Git - thirdparty/xz.git/commitdiff
xz: Free filters[] in debug mode.
authorJia Tan <jiat0218@gmail.com>
Wed, 10 May 2023 14:38:59 +0000 (22:38 +0800)
committerJia Tan <jiat0218@gmail.com>
Mon, 17 Jul 2023 15:34:55 +0000 (23:34 +0800)
This will only free filter chains created with --filters1-9 since the
default filter chain may be set from a static function variable. The
complexity to free the default filter chain is not worth the burden on
code maintenance.

src/xz/coder.c

index 476a5606a990f65540899f8524a4ef2bfdf802d4..55e59c48f7bf1b3538414fa8805708c2ddcbb67d 100644 (file)
@@ -1245,6 +1245,16 @@ coder_run(const char *filename)
 extern void
 coder_free(void)
 {
+       // Free starting from the second filter chain since the default
+       // filter chain may have its options set from a static variable
+       // in coder_set_compression_settings(). Since this is only run in
+       // debug mode and will be freed when the process ends anyway, we
+       // don't worry about freeing it.
+       for (uint32_t i = 1; i < ARRAY_SIZE(filters); i++) {
+               if (filters_init_mask & (1 << i))
+                       lzma_filters_free(filters[i], NULL);
+       }
+
        lzma_end(&strm);
        return;
 }