]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Plug memory leaks (#2183)
authorTobias Stoeckmann <stoeckmann@users.noreply.github.com>
Sun, 2 Jun 2024 23:49:26 +0000 (01:49 +0200)
committerGitHub <noreply@github.com>
Sun, 2 Jun 2024 23:49:26 +0000 (16:49 -0700)
The parsers for 7zip and xar contain memory leaks. Also the testsuite
7zip leaks memory. Plug them.

Noticed while running test suite with address sanitizer on Linux.

libarchive/archive_read_support_format_7zip.c
libarchive/archive_read_support_format_xar.c
libarchive/test/test_read_format_7zip.c

index 8573ff18f4c8d9660d0ab9a592f8f5b095aa80d7..634521d9521623bb4e3af8e932d043e887a1f554 100644 (file)
@@ -1765,6 +1765,10 @@ free_decompression(struct archive_read *a, struct _7zip *zip)
                }
                zip->stream_valid = 0;
        }
+#endif
+#ifdef HAVE_ZSTD_H
+       if (zip->zstdstream_valid)
+               ZSTD_freeDStream(zip->zstd_dstream);
 #endif
        if (zip->ppmd7_valid) {
                __archive_ppmd7_functions.Ppmd7_Free(
index 21cc7d8bb3bed9142e3c8e652cf37e9dc03f8755..b9bef05161d3e3a460dbf92face07cad0d610a3f 100644 (file)
@@ -3190,8 +3190,11 @@ xml2_read_toc(struct archive_read *a)
                        if (r == ARCHIVE_OK)
                                r = xml_start(a, name, &list);
                        xmlattr_cleanup(&list);
-                       if (r != ARCHIVE_OK)
+                       if (r != ARCHIVE_OK) {
+                               xmlFreeTextReader(reader);
+                               xmlCleanupParser();
                                return (r);
+                       }
                        if (empty)
                                xml_end(a, name);
                        break;
@@ -3316,8 +3319,10 @@ expat_read_toc(struct archive_read *a)
 
                d = NULL;
                r = rd_contents(a, &d, &outbytes, &used, xar->toc_remaining);
-               if (r != ARCHIVE_OK)
+               if (r != ARCHIVE_OK) {
+                       XML_ParserFree(parser);
                        return (r);
+               }
                xar->toc_remaining -= used;
                xar->offset += used;
                xar->toc_total += outbytes;
index 9f76705deaf2798b03a3f44db01b4978f312f615..cff82f2c3db39732de7f406d5b4f935c72780097 100644 (file)
@@ -1050,6 +1050,7 @@ test_arm_filter(const char *refname)
 
        extract_reference_file(refname);
 
+       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
        assert((a = archive_read_new()) != NULL);
        assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
        assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));
@@ -1123,6 +1124,7 @@ test_arm64_filter(const char *refname)
 
        extract_reference_file(refname);
 
+       assertEqualInt(ARCHIVE_OK, archive_read_free(a));
        assert((a = archive_read_new()) != NULL);
        assertEqualIntA(a, ARCHIVE_OK, archive_read_support_filter_all(a));
        assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_all(a));