diff options
author | Tim Kientzle <kientzle@acm.org> | 2013-12-31 09:54:34 -0800 |
---|---|---|
committer | Tim Kientzle <kientzle@acm.org> | 2013-12-31 09:54:34 -0800 |
commit | 08b59326dab47de08109c8aa190728e66cb8f5b1 (patch) | |
tree | 1faf1b251e9471433bf864605828105075acb344 | |
parent | cacc2912aae997cf5bc5b51dace7bf30f2869644 (diff) | |
download | libarchive-08b59326dab47de08109c8aa190728e66cb8f5b1.tar.gz |
Improve memory management in the large zip test
-rw-r--r-- | libarchive/archive_write_set_format_zip.c | 1 | ||||
-rw-r--r-- | libarchive/test/test_write_format_zip_large.c | 52 |
2 files changed, 39 insertions, 14 deletions
diff --git a/libarchive/archive_write_set_format_zip.c b/libarchive/archive_write_set_format_zip.c index 70e68aa1..220acc0c 100644 --- a/libarchive/archive_write_set_format_zip.c +++ b/libarchive/archive_write_set_format_zip.c @@ -253,6 +253,7 @@ archive_write_zip_options(struct archive_write *a, const char *key, } else { zip->crc32func = fake_crc32; } + return (ARCHIVE_OK); } else if (strcmp(key, "hdrcharset") == 0) { /* * Set the character set used in translating filenames. diff --git a/libarchive/test/test_write_format_zip_large.c b/libarchive/test/test_write_format_zip_large.c index 03d28633..06878b36 100644 --- a/libarchive/test/test_write_format_zip_large.c +++ b/libarchive/test/test_write_format_zip_large.c @@ -232,6 +232,28 @@ memory_read_skip(struct archive *a, void *_private, int64_t skip) return (new_position - old_position); } +static struct fileblocks * +fileblocks_new(void) +{ + struct fileblocks *fileblocks; + + fileblocks = calloc(1, sizeof(struct fileblocks)); + return fileblocks; +} + +static void +fileblocks_free(struct fileblocks *fileblocks) +{ + while (fileblocks->first != NULL) { + struct fileblock *b = fileblocks->first; + fileblocks->first = fileblocks->first->next; + free(b->buff); + free(b); + } + free(fileblocks); +} + + /* The sizes of the entries we're going to generate. */ static int64_t test_sizes[] = { /* Test for 32-bit signed overflow. */ @@ -291,7 +313,7 @@ DEFINE_TEST(test_write_format_zip_large) { int i; char namebuff[64]; - struct fileblocks fileblocks; + struct fileblocks *fileblocks = fileblocks_new(); struct archive_entry *ae; struct archive *a; int64_t filesize; @@ -300,17 +322,20 @@ DEFINE_TEST(test_write_format_zip_large) nullsize = (size_t)(1 * MB); nulldata = malloc(nullsize); memset(nulldata, 0xAA, nullsize); - memset(&fileblocks, 0, sizeof(fileblocks)); /* * Open an archive for writing. */ a = archive_write_new(); archive_write_set_format_zip(a); - archive_write_set_options(a, "zip:compression=store"); - archive_write_set_options(a, "zip:fakecrc32"); - archive_write_set_bytes_per_block(a, 0); /* No buffering. */ - archive_write_open(a, &fileblocks, NULL, memory_write, NULL); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_options(a, "zip:compression=store")); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_options(a, "zip:fakecrc32")); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_set_bytes_per_block(a, 0)); /* No buffering. */ + assertEqualIntA(a, ARCHIVE_OK, + archive_write_open(a, fileblocks, NULL, memory_write, NULL)); /* * Write a series of large files to it. @@ -321,10 +346,10 @@ DEFINE_TEST(test_write_format_zip_large) archive_entry_copy_pathname(ae, namebuff); archive_entry_set_mode(ae, S_IFREG | 0755); filesize = test_sizes[i]; - archive_entry_set_size(ae, filesize); - assertA(0 == archive_write_header(a, ae)); + assertEqualIntA(a, ARCHIVE_OK, + archive_write_header(a, ae)); archive_entry_free(ae); /* @@ -334,8 +359,8 @@ DEFINE_TEST(test_write_format_zip_large) writesize = nullsize; if ((int64_t)writesize > filesize) writesize = (size_t)filesize; - assertA((int)writesize - == archive_write_data(a, nulldata, writesize)); + assertEqualIntA(a, (int)writesize, + (int)archive_write_data(a, nulldata, writesize)); filesize -= writesize; } } @@ -346,7 +371,6 @@ DEFINE_TEST(test_write_format_zip_large) assertA(0 == archive_write_header(a, ae)); archive_entry_free(ae); - /* Close out the archive. */ assertEqualIntA(a, ARCHIVE_OK, archive_write_close(a)); assertEqualInt(ARCHIVE_OK, archive_write_free(a)); @@ -357,7 +381,7 @@ DEFINE_TEST(test_write_format_zip_large) a = archive_read_new(); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip_seekable(a)); - verify_large_zip(a, &fileblocks); + verify_large_zip(a, fileblocks); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); /* @@ -366,9 +390,9 @@ DEFINE_TEST(test_write_format_zip_large) a = archive_read_new(); assertEqualIntA(a, ARCHIVE_OK, archive_read_support_format_zip_streamable(a)); - verify_large_zip(a, &fileblocks); + verify_large_zip(a, fileblocks); assertEqualInt(ARCHIVE_OK, archive_read_free(a)); - free(fileblocks.buff); + fileblocks_free(fileblocks); free(nulldata); } |