]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Don't leak memory.
authorJoerg Sonnenberger <joerg@bec.de>
Sat, 29 Apr 2017 16:57:33 +0000 (18:57 +0200)
committerJoerg Sonnenberger <joerg@bec.de>
Sat, 29 Apr 2017 16:57:33 +0000 (18:57 +0200)
13 files changed:
cpio/test/test_option_Z_upper.c
cpio/test/test_option_a.c
cpio/test/test_option_b64encode.c
cpio/test/test_option_grzip.c
cpio/test/test_option_lrzip.c
cpio/test/test_option_lz4.c
cpio/test/test_option_lzma.c
cpio/test/test_option_lzop.c
cpio/test/test_option_uuencode.c
cpio/test/test_option_xz.c
cpio/test/test_option_y.c
cpio/test/test_option_z.c
test_utils/test_main.c

index d69a85ea58ae5c705fe4634c7187751b53c56a36..ff388427e37244d789587f55361376f09fcd6123 100644 (file)
@@ -43,17 +43,18 @@ DEFINE_TEST(test_option_Z_upper)
                if (strstr(p, "compression not available") != NULL) {
                        skipping("This version of bsdcpio was compiled "
                            "without compress support");
+                       free(p);
                        return;
                }
                failure("-Z option is broken");
                assertEqualInt(r, 0);
-               goto done;
+               free(p);
+               return;
        }
        free(p);
        /* Check that the archive file has a compress signature. */
        p = slurpfile(&s, "archive.out");
        assert(s > 2);
        assertEqualMem(p, "\x1f\x9d", 2);
-done:
        free(p);
 }
index 606de606e2c520007a63861e4d86ba404912a4b4..296387777ccf2c0d6c350b049d9982c1949cadb3 100644 (file)
@@ -96,7 +96,8 @@ DEFINE_TEST(test_option_a)
        test_create();
 
        /* Sanity check; verify that atimes really do get modified. */
-       assert((p = slurpfile(NULL, "f0")) != NULL);
+       p = slurpfile(NULL, "f0");
+       assert(p != NULL);
        free(p);
        assertEqualInt(0, stat("f0", &st));
        if (st.st_atime == files[0].atime_sec) {
index 8f6b4157c01c7dd318427553cd67fa6c0b8c6482..7c15a823060638f16923d60b69a0e3a067f8f0ef 100644 (file)
@@ -42,6 +42,7 @@ DEFINE_TEST(test_option_b64encode)
        p = slurpfile(&s, "archive.out");
        assert(s > 2);
        assertEqualMem(p, "begin-base64 644", 16);
+       free(p);
 
        /* Archive it with uuencode only. */
        assertEqualInt(0,
@@ -51,4 +52,5 @@ DEFINE_TEST(test_option_b64encode)
        p = slurpfile(&s, "archive.out");
        assert(s > 2);
        assertEqualMem(p, "begin-base64 644", 16);
+       free(p);
 }
index dfce2e064e07dd38b62c5512093cbe9a49555dc1..7e7dd2c8e6f3ea5db830622fcd910e9910aa4a73 100644 (file)
@@ -44,9 +44,10 @@ DEFINE_TEST(test_option_grzip)
            systemf("echo f | %s -o --grzip >archive.out 2>archive.err",
            testprog));
        p = slurpfile(&s, "archive.err");
-       p[s] = '\0';
+       free(p);
        /* Check that the archive file has an grzip signature. */
        p = slurpfile(&s, "archive.out");
        assert(s > 2);
        assertEqualMem(p, "GRZipII\x00\x02\x04:)", 12);
+       free(p);
 }
index a84f75157a4cc5125e5a1cd69d86bc5e1e756700..8d9c0d576cc3c3c03e1d742a167c1b914d790884 100644 (file)
@@ -44,9 +44,10 @@ DEFINE_TEST(test_option_lrzip)
            systemf("echo f | %s -o --lrzip >archive.out 2>archive.err",
            testprog));
        p = slurpfile(&s, "archive.err");
-       p[s] = '\0';
+       free(p);
        /* Check that the archive file has an lzma signature. */
        p = slurpfile(&s, "archive.out");
        assert(s > 2);
        assertEqualMem(p, "LRZI\x00", 5);
+       free(p);
 }
index afd683ddc7731da1b88875429585674be93b0896..88dfbd63bae95385d8b2614ab348f033fe465065 100644 (file)
@@ -43,6 +43,7 @@ DEFINE_TEST(test_option_lz4)
                if (strstr(p, "compression not available") != NULL) {
                        skipping("This version of bsdcpio was compiled "
                            "without lz4 support");
+                       free(p);
                        return;
                }
                /* POSIX permits different handling of the spawnp
@@ -52,6 +53,7 @@ DEFINE_TEST(test_option_lz4)
                if (strstr(p, "Can't launch") != NULL && !canLz4()) {
                        skipping("This version of bsdcpio uses an external lz4 program "
                            "but no such program is available on this system.");
+                       free(p);
                        return;
                }
                /* Some systems successfully spawn the new process,
@@ -61,6 +63,7 @@ DEFINE_TEST(test_option_lz4)
                if (strstr(p, "Can't write") != NULL && !canLz4()) {
                        skipping("This version of bsdcpio uses an external lz4 program "
                            "but no such program is available on this system.");
+                       free(p);
                        return;
                }
                /* On some systems the error won't be detected until closing
@@ -68,14 +71,18 @@ DEFINE_TEST(test_option_lz4)
                if (strstr(p, "Error closing") != NULL && !canLz4()) {
                        skipping("This version of bsdcpio uses an external lz4 program "
                            "but no such program is available on this system.");
+                       free(p);
                        return;
                }
+               free(p);
                failure("--lz4 option is broken: %s", p);
                assertEqualInt(r, 0);
                return;
        }
+       free(p);
        /* Check that the archive file has an lz4 signature. */
        p = slurpfile(&s, "archive.out");
        assert(s > 2);
        assertEqualMem(p, "\x04\x22\x4d\x18", 4);
+       free(p);
 }
index c6e33530150580eb855f1924efd0f4f18803b362..b7cad3d1e99aee4064761379d06e326f2a4d6ef8 100644 (file)
@@ -43,14 +43,18 @@ DEFINE_TEST(test_option_lzma)
                if (strstr(p, "compression not available") != NULL) {
                        skipping("This version of bsdcpio was compiled "
                            "without lzma support");
+                       free(p);
                        return;
                }
                failure("--lzma option is broken");
                assertEqualInt(r, 0);
+               free(p);
                return;
        }
+       free(p);
        /* Check that the archive file has an lzma signature. */
        p = slurpfile(&s, "archive.out");
        assert(s > 2);
        assertEqualMem(p, "\x5d\00\00", 3);
+       free(p);
 }
index 9f1666e9c5b941f7fba24b1dcd5c9e27dedd65a5..aa40ef5b6392f2d8e60c0c76b4c4acfad9567bbf 100644 (file)
@@ -39,7 +39,7 @@ DEFINE_TEST(test_option_lzop)
        r = systemf("echo f | %s -o --lzop >archive.out 2>archive.err",
            testprog);
        p = slurpfile(&s, "archive.err");
-       p[s] = '\0';
+       free(p);
        if (r != 0) {
                if (!canLzop()) {
                        skipping("lzop is not supported on this platform");
@@ -53,4 +53,5 @@ DEFINE_TEST(test_option_lzop)
        p = slurpfile(&s, "archive.out");
        assert(s > 2);
        assertEqualMem(p, "\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a", 9);
+       free(p);
 }
index ecf354f8f39102a64d0077605317e18d837308e3..a42a0e03096fcf607594cd4498d10570d4e98ad9 100644 (file)
@@ -42,6 +42,7 @@ DEFINE_TEST(test_option_uuencode)
        p = slurpfile(&s, "archive.out");
        assert(s > 2);
        assertEqualMem(p, "begin 644", 9);
+       free(p);
 
        /* Archive it with uuencode only. */
        assertEqualInt(0,
@@ -51,4 +52,5 @@ DEFINE_TEST(test_option_uuencode)
        p = slurpfile(&s, "archive.out");
        assert(s > 2);
        assertEqualMem(p, "begin 644", 9);
+       free(p);
 }
index 02b5dfaad4a1c63ff8b7a1c69c6b54b93e7f22cb..f0d3b33d45b88c0f54fb4737a3664db742f60f60 100644 (file)
@@ -44,14 +44,18 @@ DEFINE_TEST(test_option_xz)
                if (strstr(p, "compression not available") != NULL) {
                        skipping("This version of bsdcpio was compiled "
                            "without xz support");
+                       free(p);
                        return;
                }
+               free(p);
                failure("--xz option is broken");
                assertEqualInt(r, 0);
                return;
        }
+       free(p);
        /* Check that the archive file has an xz signature. */
        p = slurpfile(&s, "archive.out");
        assert(s > 2);
        assertEqualMem(p, "\xFD\x37\x7A\x58\x5A\x00", 6);
+       free(p);
 }
index 0397b3d1bf4588cac61169669054097283891709..989b5f1aaf6e49df9ea1e114eaf0aa215fe33823 100644 (file)
@@ -38,7 +38,7 @@ DEFINE_TEST(test_option_y)
        r = systemf("echo f | %s -oy >archive.out 2>archive.err",
            testprog);
        p = slurpfile(&s, "archive.err");
-       p[s] = '\0';
+       free(p);
        if (r != 0) {
                if (!canBzip2()) {
                        skipping("bzip2 is not supported on this platform");
@@ -46,14 +46,12 @@ DEFINE_TEST(test_option_y)
                }
                failure("-y option is broken");
                assertEqualInt(r, 0);
-               goto done;
+               return;
        }
        assertTextFileContents("1 block\n", "archive.err");
        /* Check that the archive file has a bzip2 signature. */
-       free(p);
        p = slurpfile(&s, "archive.out");
        assert(s > 2);
        assertEqualMem(p, "BZh9", 4);
-done:
        free(p);
 }
index 0b68a42babbf446c0a00be332471f7419a4dbf0c..803232d045c21e4c719d96df75e44b00469b9bbd 100644 (file)
@@ -38,7 +38,7 @@ DEFINE_TEST(test_option_z)
        r = systemf("echo f | %s -oz >archive.out 2>archive.err",
            testprog);
        p = slurpfile(&s, "archive.err");
-       p[s] = '\0';
+       free(p);
        if (r != 0) {
                if (!canGzip()) {
                        skipping("gzip is not supported on this platform");
@@ -52,4 +52,5 @@ DEFINE_TEST(test_option_z)
        p = slurpfile(&s, "archive.out");
        assert(s > 4);
        assertEqualMem(p, "\x1f\x8b\x08\x00", 4);
+       free(p);
 }
index d74045934bec7a209d57ee050da988af881d550b..0e1413693f4a86807e35d97aeef079cae3500a21 100644 (file)
@@ -1102,6 +1102,7 @@ assertion_file_contains_lines_any_order(const char *file, int line,
                        failure_start(pathname, line, "Can't allocate memory");
                        failure_finish(NULL);
                        free(expected);
+                       free(buff);
                        return (0);
                }
                for (i = 0; lines[i] != NULL; ++i) {
@@ -1124,6 +1125,7 @@ assertion_file_contains_lines_any_order(const char *file, int line,
                        failure_start(pathname, line, "Can't allocate memory");
                        failure_finish(NULL);
                        free(expected);
+                       free(buff);
                        return (0);
                }
                for (j = 0, p = buff; p < buff + buff_size;