]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix the potential of memory leaks in our test suit.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 4 Oct 2014 15:56:47 +0000 (00:56 +0900)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Sat, 4 Oct 2014 15:56:47 +0000 (00:56 +0900)
libarchive/test/test_fuzz.c
libarchive/test/test_write_format_zip.c
libarchive/test/test_write_format_zip_large.c
tar/test/test_option_b.c

index cd8f7e0d5549cefd57a6f5058eba4b0a849aa6b5..e3bf24c0ffa13e72374147960ca7ed5cbebb63ba 100644 (file)
@@ -123,8 +123,10 @@ test_fuzz(const struct files *filesets)
                        continue;
                image = malloc(size);
                assert(image != NULL);
-               if (image == NULL)
+               if (image == NULL) {
+                       free(rawimage);
                        return;
+               }
                srand((unsigned)time(NULL));
 
                for (i = 0; i < 100; ++i) {
index 879451d8bed0a21252f11b67316a74f5da3ec253..a7ca434f8ea98ff9df199e6b1754e81ecc16d3d4 100644 (file)
@@ -685,6 +685,7 @@ DEFINE_TEST(test_write_format_zip_traditional_pkware_encryption)
                    "zip:encryption=zipcrypt")) {
                skipping("This system does not have cryptographic liberary");
                archive_write_free(a);
+               free(buff);
                return;
        }
        assertEqualIntA(a, ARCHIVE_OK,
@@ -764,6 +765,7 @@ DEFINE_TEST(test_write_format_zip_winzip_aes128_encryption)
        {
                skipping("This system does not have cryptographic liberary");
                archive_write_free(a);
+               free(buff);
                return;
        }
        assertEqualIntA(a, ARCHIVE_OK,
@@ -843,6 +845,7 @@ DEFINE_TEST(test_write_format_zip_winzip_aes256_encryption)
        {
                skipping("This system does not have cryptographic liberary");
                archive_write_free(a);
+               free(buff);
                return;
        }
        assertEqualIntA(a, ARCHIVE_OK,
index e8a8b0ea3ca09dc6e6e42801ac3c57bc171f0da7..12cd1059d1c8568bedb0c8f29373ea97c62281ba 100644 (file)
@@ -179,10 +179,8 @@ memory_read_seek(struct archive *a, void *_private, int64_t offset, int whence)
        (void)a;
        if (whence == SEEK_END) {
                offset = private->filesize + offset;
-               whence = SEEK_SET;
        } else if (whence == SEEK_CUR) {
                offset = private->fileposition + offset;
-               whence = SEEK_SET;
        }
 
        if (offset < 0) {
index 6fea474febbda4259c30af42cc77aa27cec11e50..81f50be8355eb29f5ddc909e6e2ac9e38e96f55f 100644 (file)
@@ -29,15 +29,16 @@ __FBSDID("$FreeBSD$");
 
 DEFINE_TEST(test_option_b)
 {
-       char *testprog_ustar = malloc(strlen(testprog) + sizeof(USTAR_OPT) + 1);
-       strcpy(testprog_ustar, testprog);
-       strcat(testprog_ustar, USTAR_OPT);
+       char *testprog_ustar;
 
        assertMakeFile("file1", 0644, "file1");
        if (systemf("cat file1 > test_cat.out 2> test_cat.err") != 0) {
                skipping("Platform doesn't have cat");
                return;
        }
+       testprog_ustar = malloc(strlen(testprog) + sizeof(USTAR_OPT) + 1);
+       strcpy(testprog_ustar, testprog);
+       strcat(testprog_ustar, USTAR_OPT);
 
        /*
         * Bsdtar does not pad if the output is going directly to a disk file.