1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-16 10:20:30 +00:00

Clean up a lot of memory leaks in the libarchive test harness.

This commit is contained in:
Tim Kientzle 2007-04-15 04:30:02 +00:00
parent edddd60899
commit 0c3e4592a6
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=168745
12 changed files with 29 additions and 0 deletions

View File

@ -174,6 +174,7 @@ compare_acls(struct archive_entry *ae, struct acl_t *acls, int n, int mode)
acls[marker[0]].type, acls[marker[0]].permset,
acls[marker[0]].tag, acls[marker[0]].qual, acls[marker[0]].name);
assert(n == 0); /* Number of ACLs not matched should == 0 */
free(marker);
}
DEFINE_TEST(test_acl_basic)
@ -224,4 +225,5 @@ DEFINE_TEST(test_acl_basic)
failure("Basic ACLs should set mode to 0142, not %04o",
archive_entry_mode(ae)&0777);
assert((archive_entry_mode(ae) & 0777) == 0142);
archive_entry_free(ae);
}

View File

@ -397,6 +397,7 @@ compare_acls(struct archive_entry *ae, struct acl_t *acls, int n, int mode)
acls[marker[0]].type, acls[marker[0]].permset,
acls[marker[0]].tag, acls[marker[0]].qual, acls[marker[0]].name);
assert(n == 0); /* Number of ACLs not matched should == 0 */
free(marker);
}
DEFINE_TEST(test_acl_pax)
@ -441,6 +442,7 @@ DEFINE_TEST(test_acl_pax)
*/
set_acls(ae, acls0, sizeof(acls0)/sizeof(acls0[0]));
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/* Close out the archive. */
assertA(0 == archive_write_close(a));

View File

@ -62,6 +62,7 @@ DEFINE_TEST(test_read_data_large)
buff2[i] = (unsigned char)rand();
archive_entry_set_size(ae, sizeof(buff2));
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
assertA(sizeof(buff2) == archive_write_data(a, buff2, sizeof(buff2)));
/* Close out the archive. */

View File

@ -55,6 +55,7 @@ DEFINE_TEST(test_read_extract)
archive_entry_copy_pathname(ae, "dir_0775");
archive_entry_set_mode(ae, S_IFDIR | 0775);
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/* A regular file. */
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "file");
@ -70,32 +71,38 @@ DEFINE_TEST(test_read_extract)
archive_entry_copy_pathname(ae, "dir");
archive_entry_set_mode(ae, S_IFDIR | 0777);
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/* A file in the directory. */
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "dir/file");
archive_entry_set_mode(ae, S_IFREG | 0700);
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/* A file in a dir that is not already in the archive. */
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "dir2/file");
archive_entry_set_mode(ae, S_IFREG | 0000);
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/* A dir with a trailing /. */
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "dir3/.");
archive_entry_set_mode(ae, S_IFDIR | 0710);
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/* Multiple dirs with a single entry. */
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "dir4/a/../b/../c/");
archive_entry_set_mode(ae, S_IFDIR | 0711);
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/* A symlink. */
assert((ae = archive_entry_new()) != NULL);
archive_entry_copy_pathname(ae, "symlink");
archive_entry_set_mode(ae, S_IFLNK | 0755);
archive_entry_set_symlink(ae, "file");
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/* Close out the archive. */
assertA(0 == archive_write_close(a));
#if ARCHIVE_API_VERSION > 1

View File

@ -50,6 +50,7 @@ DEFINE_TEST(test_read_large)
archive_entry_set_mode(entry, S_IFREG | 0777);
archive_entry_set_pathname(entry, "test");
assertA(0 == archive_write_header(a, entry));
archive_entry_free(entry);
assertA(sizeof(testdata) == archive_write_data(a, testdata, sizeof(testdata)));
#if ARCHIVE_API_VERSION > 1
assertA(0 == archive_write_finish(a));

View File

@ -47,6 +47,7 @@ DEFINE_TEST(test_read_position)
assertA(0 == archive_write_set_bytes_per_block(a, 512));
assertA(0 == archive_write_open_memory(a, buff, sizeof(buff), &write_pos));
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
assertA(data_size == archive_write_data(a, nulls, sizeof(nulls)));
#if ARCHIVE_API_VERSION > 1
assertA(0 == archive_write_finish(a));

View File

@ -51,6 +51,7 @@ DEFINE_TEST(test_read_truncated)
buff2[i] = (unsigned char)rand();
archive_entry_set_size(ae, sizeof(buff2));
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
assertA(sizeof(buff2) == archive_write_data(a, buff2, sizeof(buff2)));
/* Close out the archive. */

View File

@ -66,6 +66,7 @@ test_filename(int dlen, int flen)
archive_entry_set_mode(ae, S_IFREG | 0755);
failure("Pathname %d/%d", dlen, flen);
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/*
* Write a dir to it (without trailing '/').
@ -75,6 +76,7 @@ test_filename(int dlen, int flen)
archive_entry_set_mode(ae, S_IFDIR | 0755);
failure("Dirname %d/%d", dlen, flen);
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/* Tar adds a '/' to directory names. */
strcat(dirname, "/");
@ -87,6 +89,7 @@ test_filename(int dlen, int flen)
archive_entry_set_mode(ae, S_IFDIR | 0755);
failure("Dirname %d/%d", dlen, flen);
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
/* Close out the archive. */
assertA(0 == archive_write_close(a));

View File

@ -135,6 +135,7 @@ DEFINE_TEST(test_write_disk_perms)
archive_entry_set_mode(ae, S_IFREG | 0777);
assert(0 == archive_write_header(a, ae));
assert(0 == archive_write_finish_entry(a));
archive_entry_free(ae);
/* Write a regular file, then write over it. */
/* For files, the perms should get updated. */
@ -142,6 +143,7 @@ DEFINE_TEST(test_write_disk_perms)
archive_entry_copy_pathname(ae, "file_overwrite_0144");
archive_entry_set_mode(ae, S_IFREG | 0777);
assert(0 == archive_write_header(a, ae));
archive_entry_free(ae);
assert(0 == archive_write_finish_entry(a));
/* Check that file was created with different perms. */
assert(0 == stat("file_overwrite_0144", &st));
@ -152,6 +154,7 @@ DEFINE_TEST(test_write_disk_perms)
archive_entry_copy_pathname(ae, "file_overwrite_0144");
archive_entry_set_mode(ae, S_IFREG | 0144);
assert(0 == archive_write_header(a, ae));
archive_entry_free(ae);
assert(0 == archive_write_finish_entry(a));
/* Write a regular dir. */
@ -159,6 +162,7 @@ DEFINE_TEST(test_write_disk_perms)
archive_entry_copy_pathname(ae, "dir_0514");
archive_entry_set_mode(ae, S_IFDIR | 0514);
assert(0 == archive_write_header(a, ae));
archive_entry_free(ae);
assert(0 == archive_write_finish_entry(a));
/* Overwrite an existing dir. */
@ -173,6 +177,7 @@ DEFINE_TEST(test_write_disk_perms)
archive_entry_copy_pathname(ae, "dir_overwrite_0744");
archive_entry_set_mode(ae, S_IFDIR | 0777);
assert(0 == archive_write_header(a, ae));
archive_entry_free(ae);
assert(0 == archive_write_finish_entry(a));
/* Make sure they're unchanged. */
assert(0 == stat("dir_overwrite_0744", &st));
@ -305,6 +310,7 @@ DEFINE_TEST(test_write_disk_perms)
#else
archive_write_finish(a);
#endif
archive_entry_free(ae);
/* Test the entries on disk. */
assert(0 == stat("file_0755", &st));

View File

@ -49,6 +49,7 @@ DEFINE_TEST(test_write_disk_secure)
archive_entry_copy_pathname(ae, "dir");
archive_entry_set_mode(ae, S_IFDIR | 0777);
assert(0 == archive_write_header(a, ae));
archive_entry_free(ae);
assert(0 == archive_write_finish_entry(a));
/* Write a symlink to the dir above. */
@ -77,6 +78,7 @@ DEFINE_TEST(test_write_disk_secure)
archive_write_disk_set_options(a, ARCHIVE_EXTRACT_SECURE_SYMLINKS);
failure("Extracting a file through a symlink should fail here.");
assertEqualInt(ARCHIVE_WARN, archive_write_header(a, ae));
archive_entry_free(ae);
assert(0 == archive_write_finish_entry(a));
/* Create another link. */
@ -97,6 +99,7 @@ DEFINE_TEST(test_write_disk_secure)
archive_entry_set_mode(ae, S_IFREG | 0777);
archive_write_disk_set_options(a, ARCHIVE_EXTRACT_SECURE_SYMLINKS | ARCHIVE_EXTRACT_UNLINK);
assertEqualIntA(a, ARCHIVE_OK, archive_write_header(a, ae));
archive_entry_free(ae);
assert(0 == archive_write_finish_entry(a));

View File

@ -65,6 +65,7 @@ DEFINE_TEST(test_write_format_tar)
archive_entry_set_size(ae, 8);
assertA(0 == archive_write_header(a, ae));
archive_entry_free(ae);
assertA(8 == archive_write_data(a, "12345678", 9));
/* Close out the archive. */

View File

@ -72,4 +72,5 @@ DEFINE_TEST(test_write_open_memory)
assert(buff[i] == 0xAE);
assert(s <= i);
}
archive_entry_free(ae);
}