summaryrefslogtreecommitdiff
path: root/tar/test
diff options
context:
space:
mode:
authorNgie Cooper <yanegomi@gmail.com>2016-12-10 16:34:51 -0800
committerNgie Cooper <yanegomi@gmail.com>2016-12-10 17:15:46 -0800
commit067829f98b903e5c9021d4056aeff43cca27e59e (patch)
tree84d1b403bbecb4e4de44aa761ebe10bd445081cf /tar/test
parent242f510fb0b478df8de89e76916b5e612288ff9a (diff)
downloadlibarchive-067829f98b903e5c9021d4056aeff43cca27e59e.tar.gz
Free p (the memory allocated via slurpfile) when done with the contents
Reported by: Coverity CID: 1331627-1331630, 1355332, 1331634-1331645, 1331647, 1355331
Diffstat (limited to 'tar/test')
-rw-r--r--tar/test/test_leading_slash.c1
-rw-r--r--tar/test/test_option_a.c7
-rw-r--r--tar/test/test_option_b64encode.c2
-rw-r--r--tar/test/test_option_gid_gname.c4
-rw-r--r--tar/test/test_option_grzip.c3
-rw-r--r--tar/test/test_option_j.c7
-rw-r--r--tar/test/test_option_lrzip.c2
-rw-r--r--tar/test/test_option_lz4.c12
-rw-r--r--tar/test/test_option_lzma.c5
-rw-r--r--tar/test/test_option_lzop.c7
-rw-r--r--tar/test/test_option_r.c34
-rw-r--r--tar/test/test_option_uid_uname.c5
-rw-r--r--tar/test/test_option_uuencode.c2
-rw-r--r--tar/test/test_option_xz.c7
-rw-r--r--tar/test/test_option_z.c7
-rw-r--r--tar/test/test_stdio.c1
-rw-r--r--tar/test/test_version.c3
17 files changed, 77 insertions, 32 deletions
diff --git a/tar/test/test_leading_slash.c b/tar/test/test_leading_slash.c
index a8921ebc..572c45e3 100644
--- a/tar/test/test_leading_slash.c
+++ b/tar/test/test_leading_slash.c
@@ -44,6 +44,7 @@ DEFINE_TEST(test_leading_slash)
if (assertFileExists("test.err")) {
errfile = slurpfile(&errfile_size, "test.err");
assert(strstr(errfile, expected_errmsg) != NULL);
+ free(errfile);
}
}
diff --git a/tar/test/test_option_a.c b/tar/test/test_option_a.c
index a000621c..d9eed877 100644
--- a/tar/test/test_option_a.c
+++ b/tar/test/test_option_a.c
@@ -43,6 +43,7 @@ DEFINE_TEST(test_option_a)
assert(s > 2);
failure("The archive should be compressed");
assertEqualMem(p, "\x1f\x9d", 2);
+ free(p);
/* Test2: archive it with .taZ suffix. */
assertEqualInt(0,
@@ -53,6 +54,7 @@ DEFINE_TEST(test_option_a)
assert(s > 2);
failure("The archive should be compressed");
assertEqualMem(p, "\x1f\x9d", 2);
+ free(p);
/* Test3: archive it with .tar.Z.uu suffix. */
assertEqualInt(0,
@@ -63,6 +65,7 @@ DEFINE_TEST(test_option_a)
assert(s > 12);
failure("The archive should be uuencoded");
assertEqualMem(p, "begin 644 -\n", 12);
+ free(p);
/* Test4: archive it with .zip suffix. */
assertEqualInt(0,
@@ -73,6 +76,7 @@ DEFINE_TEST(test_option_a)
assert(s > 4);
failure("The archive should be zipped");
assertEqualMem(p, "\x50\x4b\x03\x04", 4);
+ free(p);
/* Test5: archive it with .tar.Z suffix and --uuencode option. */
assertEqualInt(0,
@@ -84,6 +88,7 @@ DEFINE_TEST(test_option_a)
assert(s > 2);
failure("The archive should be compressed, ignoring --uuencode option");
assertEqualMem(p, "\x1f\x9d", 2);
+ free(p);
/* Test6: archive it with .xxx suffix(unknown suffix) and
* --uuencode option. */
@@ -96,6 +101,7 @@ DEFINE_TEST(test_option_a)
assert(s > 12);
failure("The archive should be uuencoded");
assertEqualMem(p, "begin 644 -\n", 12);
+ free(p);
/* Test7: archive it with .tar.Z suffix using a long-name option. */
assertEqualInt(0,
@@ -107,4 +113,5 @@ DEFINE_TEST(test_option_a)
assert(s > 2);
failure("The archive should be compressed");
assertEqualMem(p, "\x1f\x9d", 2);
+ free(p);
}
diff --git a/tar/test/test_option_b64encode.c b/tar/test/test_option_b64encode.c
index 1e7c5717..1d042043 100644
--- a/tar/test/test_option_b64encode.c
+++ b/tar/test/test_option_b64encode.c
@@ -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);
}
diff --git a/tar/test/test_option_gid_gname.c b/tar/test/test_option_gid_gname.c
index e45da5b9..4e5f51c8 100644
--- a/tar/test/test_option_gid_gname.c
+++ b/tar/test/test_option_gid_gname.c
@@ -53,6 +53,7 @@ DEFINE_TEST(test_option_gid_gname)
/* Should force gid and gname fields in ustar header. */
assertEqualMem(data + 116, "000021 \0", 8);
assertEqualMem(data + 297, "foofoofoo\0", 10);
+ free(data);
/* Again with just --gname */
failure("Error invoking %s c", testprog);
@@ -65,6 +66,8 @@ DEFINE_TEST(test_option_gid_gname)
/* Gid should be unchanged from original reference. */
assertEqualMem(data + 116, reference + 116, 8);
assertEqualMem(data + 297, "foofoofoo\0", 10);
+ free(data);
+ free(reference);
/* Again with --gid and force gname to empty. */
failure("Error invoking %s c", testprog);
@@ -77,6 +80,7 @@ DEFINE_TEST(test_option_gid_gname)
assertEqualMem(data + 116, "000021 \0", 8);
/* Gname field in ustar header should be empty. */
assertEqualMem(data + 297, "\0", 1);
+ free(data);
/* TODO: It would be nice to verify that --gid= by itself
* will look up the associated gname and use that, but
diff --git a/tar/test/test_option_grzip.c b/tar/test/test_option_grzip.c
index 5132eeec..fbff2524 100644
--- a/tar/test/test_option_grzip.c
+++ b/tar/test/test_option_grzip.c
@@ -45,8 +45,11 @@ DEFINE_TEST(test_option_grzip)
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);
}
diff --git a/tar/test/test_option_j.c b/tar/test/test_option_j.c
index 3202c3b8..838234a2 100644
--- a/tar/test/test_option_j.c
+++ b/tar/test/test_option_j.c
@@ -42,15 +42,18 @@ DEFINE_TEST(test_option_j)
if (r != 0) {
if (!canBzip2()) {
skipping("bzip2 is not supported on this platform");
- return;
+ goto done;
}
failure("-j option is broken");
assertEqualInt(r, 0);
- return;
+ goto done;
}
+ free(p);
assertEmptyFile("archive.err");
/* Check that the archive file has a bzip2 signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "BZh9", 4);
+done:
+ free(p);
}
diff --git a/tar/test/test_option_lrzip.c b/tar/test/test_option_lrzip.c
index d3486a3a..11e9827e 100644
--- a/tar/test/test_option_lrzip.c
+++ b/tar/test/test_option_lrzip.c
@@ -45,8 +45,10 @@ DEFINE_TEST(test_option_lrzip)
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);
}
diff --git a/tar/test/test_option_lz4.c b/tar/test/test_option_lz4.c
index 5dc94521..1694e3ce 100644
--- a/tar/test/test_option_lz4.c
+++ b/tar/test/test_option_lz4.c
@@ -43,7 +43,7 @@ DEFINE_TEST(test_option_lz4)
if (strstr(p, "Unsupported compression") != NULL) {
skipping("This version of bsdtar was compiled "
"without lz4 support");
- return;
+ goto done;
}
/* POSIX permits different handling of the spawnp
* system call used to launch the subsidiary
@@ -52,7 +52,7 @@ DEFINE_TEST(test_option_lz4)
if (strstr(p, "Can't launch") != NULL && !canLz4()) {
skipping("This version of bsdtar uses an external lz4 program "
"but no such program is available on this system.");
- return;
+ goto done;
}
/* Some systems successfully spawn the new process,
* but fail to exec a program within that process.
@@ -61,14 +61,18 @@ DEFINE_TEST(test_option_lz4)
if (strstr(p, "Can't write") != NULL && !canLz4()) {
skipping("This version of bsdtar uses an external lz4 program "
"but no such program is available on this system.");
- return;
+ goto done;
}
failure("--lz4 option is broken: %s", p);
assertEqualInt(r, 0);
- return;
+ goto done;
}
+ 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);
+
+done:
+ free(p);
}
diff --git a/tar/test/test_option_lzma.c b/tar/test/test_option_lzma.c
index a845666e..a618ff8a 100644
--- a/tar/test/test_option_lzma.c
+++ b/tar/test/test_option_lzma.c
@@ -48,10 +48,13 @@ DEFINE_TEST(test_option_lzma)
}
failure("--lzma option is broken");
assertEqualInt(r, 0);
- return;
+ goto done;
}
+ 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);
+done:
+ free(p);
}
diff --git a/tar/test/test_option_lzop.c b/tar/test/test_option_lzop.c
index 1145499a..20ef06c5 100644
--- a/tar/test/test_option_lzop.c
+++ b/tar/test/test_option_lzop.c
@@ -42,14 +42,17 @@ DEFINE_TEST(test_option_lzop)
if (r != 0) {
if (!canLzop()) {
skipping("lzop is not supported on this platform");
- return;
+ goto done;
}
failure("--lzop option is broken");
assertEqualInt(r, 0);
- return;
+ goto done;
}
+ free(p);
/* Check that the archive file has an lzma signature. */
p = slurpfile(&s, "archive.out");
assert(s > 2);
assertEqualMem(p, "\x89\x4c\x5a\x4f\x00\x0d\x0a\x1a\x0a", 9);
+done:
+ free(p);
}
diff --git a/tar/test/test_option_r.c b/tar/test/test_option_r.c
index 77876857..287e8093 100644
--- a/tar/test/test_option_r.c
+++ b/tar/test/test_option_r.c
@@ -36,6 +36,10 @@ DEFINE_TEST(test_option_r)
size_t s, buff_size_rounded;
int r, i;
+ buff = NULL;
+ p0 = NULL;
+ p1 = NULL;
+
/* Create an archive with one file. */
assertMakeFile("f1", 0644, "abc");
r = systemf("%s cf archive.tar --format=ustar f1 >step1.out 2>step1.err", testprog);
@@ -47,11 +51,9 @@ DEFINE_TEST(test_option_r)
/* Do some basic validation of the constructed archive. */
p0 = slurpfile(&s, "archive.tar");
if (!assert(p0 != NULL))
- return;
- if (!assert(s >= 2048)) {
- free(p0);
- return;
- }
+ goto done;
+ if (!assert(s >= 2048))
+ goto done;
assertEqualMem(p0 + 0, "f1", 3);
assertEqualMem(p0 + 512, "abc", 3);
assertEqualMem(p0 + 1024, "\0\0\0\0\0\0\0\0", 8);
@@ -60,10 +62,8 @@ DEFINE_TEST(test_option_r)
/* Edit that file with a lot more data and update the archive with a new copy. */
buff = malloc(buff_size);
assert(buff != NULL);
- if (buff == NULL) {
- free(p0);
- return;
- }
+ if (buff == NULL)
+ goto done;
for (i = 0; i < (int)buff_size; ++i)
buff[i] = "abcdefghijklmnopqrstuvwxyz"[rand() % 26];
@@ -77,10 +77,8 @@ DEFINE_TEST(test_option_r)
/* The constructed archive should just have the new entry appended. */
p1 = slurpfile(&s, "archive.tar");
- if (!assert(p1 != NULL)) {
- free(p0);
- return;
- }
+ if (!assert(p1 != NULL))
+ goto done;
buff_size_rounded = ((buff_size + 511) / 512) * 512;
assert(s >= 2560 + buff_size_rounded);
/* Verify first entry is unchanged. */
@@ -105,10 +103,8 @@ DEFINE_TEST(test_option_r)
/* Validate the constructed archive. */
p1 = slurpfile(&s, "archive.tar");
- if (!assert(p1 != NULL)) {
- free(p0);
- return;
- }
+ if (!assert(p1 != NULL))
+ goto done;
assert(s >= 3584 + buff_size_rounded);
/* Verify first two entries are unchanged. */
assertEqualMem(p0, p1, 1536 + buff_size_rounded);
@@ -118,7 +114,6 @@ DEFINE_TEST(test_option_r)
/* Verify end-of-archive marker. */
assertEqualMem(p1 + 2560 + buff_size_rounded, "\0\0\0\0\0\0\0\0", 8);
assertEqualMem(p1 + 3072 + buff_size_rounded, "\0\0\0\0\0\0\0\0", 8);
- free(p0);
free(p1);
/* Unpack everything */
@@ -132,4 +127,7 @@ DEFINE_TEST(test_option_r)
/* Verify that the second copy of f1 overwrote the first. */
assertFileContents(buff, (int)strlen(buff), "f1");
+done:
+ free(buff);
+ free(p0);
}
diff --git a/tar/test/test_option_uid_uname.c b/tar/test/test_option_uid_uname.c
index 83ea5f1e..0a8a9bb2 100644
--- a/tar/test/test_option_uid_uname.c
+++ b/tar/test/test_option_uid_uname.c
@@ -53,6 +53,7 @@ DEFINE_TEST(test_option_uid_uname)
/* Should force uid and uname fields in ustar header. */
assertEqualMem(data + 108, "000021 \0", 8);
assertEqualMem(data + 265, "foofoofoo\0", 10);
+ free(data);
/* Again with just --uid */
failure("Error invoking %s c", testprog);
@@ -65,6 +66,7 @@ DEFINE_TEST(test_option_uid_uname)
assertEqualMem(data + 108, "000021 \0", 8);
/* Uname field in ustar header should be empty. */
assertEqualMem(data + 265, "\0", 1);
+ free(data);
/* Again with just --uname */
failure("Error invoking %s c", testprog);
@@ -77,4 +79,7 @@ DEFINE_TEST(test_option_uid_uname)
/* Uid should be unchanged from original reference. */
assertEqualMem(data + 108, reference + 108, 8);
assertEqualMem(data + 265, "foofoofoo\0", 10);
+ free(data);
+
+ free(reference);
}
diff --git a/tar/test/test_option_uuencode.c b/tar/test/test_option_uuencode.c
index cdc6babd..a28a8e34 100644
--- a/tar/test/test_option_uuencode.c
+++ b/tar/test/test_option_uuencode.c
@@ -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);
}
diff --git a/tar/test/test_option_xz.c b/tar/test/test_option_xz.c
index 7387a604..91da0730 100644
--- a/tar/test/test_option_xz.c
+++ b/tar/test/test_option_xz.c
@@ -44,14 +44,17 @@ DEFINE_TEST(test_option_xz)
if (strstr(p, "Unsupported compression") != NULL) {
skipping("This version of bsdtar was compiled "
"without xz support");
- return;
+ goto done;
}
failure("--xz option is broken");
assertEqualInt(r, 0);
- return;
+ goto done;
}
+ 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);
+done:
+ free(p);
}
diff --git a/tar/test/test_option_z.c b/tar/test/test_option_z.c
index 1f952abe..59744999 100644
--- a/tar/test/test_option_z.c
+++ b/tar/test/test_option_z.c
@@ -42,14 +42,17 @@ DEFINE_TEST(test_option_z)
if (r != 0) {
if (!canGzip()) {
skipping("gzip is not supported on this platform");
- return;
+ goto done;
}
failure("-z option is broken");
assertEqualInt(r, 0);
- return;
+ goto done;
}
+ free(p);
/* Check that the archive file has a gzip signature. */
p = slurpfile(&s, "archive.out");
assert(s > 4);
assertEqualMem(p, "\x1f\x8b\x08\x00", 4);
+done:
+ free(p);
}
diff --git a/tar/test/test_stdio.c b/tar/test/test_stdio.c
index bf5dd774..d6650a5e 100644
--- a/tar/test/test_stdio.c
+++ b/tar/test/test_stdio.c
@@ -116,6 +116,7 @@ DEFINE_TEST(test_stdio)
assertEqualInt((int)s, 3);
assertEqualMem(p, "abc", 3);
/* TODO: Verify xvf.err */
+ free(p);
/* 'xvf -' should generate list on stderr, empty stdout. */
r = systemf("%s xvf - < archive >xvf-.out 2>xvf-.err", testprog);
diff --git a/tar/test/test_version.c b/tar/test/test_version.c
index 04d9e6c7..0c904d70 100644
--- a/tar/test/test_version.c
+++ b/tar/test/test_version.c
@@ -53,7 +53,7 @@ DEFINE_TEST(test_version)
assert(s > 6);
failure("Version must start with 'bsdtar': ``%s''", p);
if (!assertEqualMem(q, "bsdtar ", 7))
- return;
+ goto done;
q += 7; s -= 7;
/* Version number is a series of digits and periods. */
while (s > 0 && (*q == '.' || (*q >= '0' && *q <= '9'))) {
@@ -98,5 +98,6 @@ DEFINE_TEST(test_version)
failure("Version output must end with \\n or \\r\\n");
if (*q == '\r') { ++q; --s; }
assertEqualMem(q, "\n", 1);
+done:
free(p);
}