summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-07-18 20:31:54 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-07-18 20:31:54 (GMT)
commitf63ac61fbf512ac9446a86bfd9c07b33d4c1e558 (patch)
treeca5508c1b830de8f3ea1f2225c60b89373166e3d /t
parent44357f64f661635661275fe71e194974a3302049 (diff)
parentf40a693450853fda1b121d7d8c082271c54d03fb (diff)
downloadgit-f63ac61fbf512ac9446a86bfd9c07b33d4c1e558.zip
git-f63ac61fbf512ac9446a86bfd9c07b33d4c1e558.tar.gz
git-f63ac61fbf512ac9446a86bfd9c07b33d4c1e558.tar.bz2
Merge branch 'ab/test-tool-leakfix'
Plug various memory leaks in test-tool commands. * ab/test-tool-leakfix: test-tool delta: fix a memory leak test-tool ref-store: fix a memory leak test-tool bloom: fix memory leaks test-tool json-writer: fix memory leaks test-tool regex: call regfree(), fix memory leaks test-tool urlmatch-normalization: fix a memory leak test-tool {dump,scrap}-cache-tree: fix memory leaks test-tool path-utils: fix a memory leak test-tool test-hash: fix a memory leak
Diffstat (limited to 't')
-rw-r--r--t/helper/test-bloom.c2
-rw-r--r--t/helper/test-delta.c21
-rw-r--r--t/helper/test-dump-cache-tree.c7
-rw-r--r--t/helper/test-hash.c1
-rw-r--r--t/helper/test-json-writer.c16
-rw-r--r--t/helper/test-path-utils.c11
-rw-r--r--t/helper/test-ref-store.c1
-rw-r--r--t/helper/test-regex.c9
-rw-r--r--t/helper/test-scrap-cache-tree.c1
-rw-r--r--t/helper/test-urlmatch-normalization.c11
-rwxr-xr-xt/t0015-hash.sh3
-rwxr-xr-xt/t0019-json-writer.sh2
-rwxr-xr-xt/t0060-path-utils.sh1
-rwxr-xr-xt/t0090-cache-tree.sh2
-rwxr-xr-xt/t0095-bloom.sh2
-rwxr-xr-xt/t0110-urlmatch-normalization.sh2
-rwxr-xr-xt/t5303-pack-corruption-resilience.sh2
-rwxr-xr-xt/t5308-pack-detect-duplicates.sh2
-rwxr-xr-xt/t5309-pack-delta-cycles.sh2
-rwxr-xr-xt/t5321-pack-large-objects.sh2
-rwxr-xr-xt/t7812-grep-icase-non-ascii.sh1
21 files changed, 77 insertions, 24 deletions
diff --git a/t/helper/test-bloom.c b/t/helper/test-bloom.c
index ad3ef1c..6c900ca 100644
--- a/t/helper/test-bloom.c
+++ b/t/helper/test-bloom.c
@@ -16,6 +16,7 @@ static void add_string_to_filter(const char *data, struct bloom_filter *filter)
}
printf("\n");
add_key_to_filter(&key, filter, &settings);
+ clear_bloom_key(&key);
}
static void print_bloom_filter(struct bloom_filter *filter) {
@@ -80,6 +81,7 @@ int cmd__bloom(int argc, const char **argv)
}
print_bloom_filter(&filter);
+ free(filter.data);
}
if (!strcmp(argv[1], "get_filter_for_commit")) {
diff --git a/t/helper/test-delta.c b/t/helper/test-delta.c
index e749a49..b15481e 100644
--- a/t/helper/test-delta.c
+++ b/t/helper/test-delta.c
@@ -20,8 +20,9 @@ int cmd__delta(int argc, const char **argv)
{
int fd;
struct stat st;
- void *from_buf, *data_buf, *out_buf;
+ void *from_buf = NULL, *data_buf = NULL, *out_buf = NULL;
unsigned long from_size, data_size, out_size;
+ int ret = 1;
if (argc != 5 || (strcmp(argv[1], "-d") && strcmp(argv[1], "-p"))) {
fprintf(stderr, "usage: %s\n", usage_str);
@@ -38,21 +39,21 @@ int cmd__delta(int argc, const char **argv)
if (read_in_full(fd, from_buf, from_size) < 0) {
perror(argv[2]);
close(fd);
- return 1;
+ goto cleanup;
}
close(fd);
fd = open(argv[3], O_RDONLY);
if (fd < 0 || fstat(fd, &st)) {
perror(argv[3]);
- return 1;
+ goto cleanup;
}
data_size = st.st_size;
data_buf = xmalloc(data_size);
if (read_in_full(fd, data_buf, data_size) < 0) {
perror(argv[3]);
close(fd);
- return 1;
+ goto cleanup;
}
close(fd);
@@ -66,14 +67,20 @@ int cmd__delta(int argc, const char **argv)
&out_size);
if (!out_buf) {
fprintf(stderr, "delta operation failed (returned NULL)\n");
- return 1;
+ goto cleanup;
}
fd = open (argv[4], O_WRONLY|O_CREAT|O_TRUNC, 0666);
if (fd < 0 || write_in_full(fd, out_buf, out_size) < 0) {
perror(argv[4]);
- return 1;
+ goto cleanup;
}
- return 0;
+ ret = 0;
+cleanup:
+ free(from_buf);
+ free(data_buf);
+ free(out_buf);
+
+ return ret;
}
diff --git a/t/helper/test-dump-cache-tree.c b/t/helper/test-dump-cache-tree.c
index 6a3f88f..0d6d7f1 100644
--- a/t/helper/test-dump-cache-tree.c
+++ b/t/helper/test-dump-cache-tree.c
@@ -59,11 +59,16 @@ int cmd__dump_cache_tree(int ac, const char **av)
{
struct index_state istate;
struct cache_tree *another = cache_tree();
+ int ret;
+
setup_git_directory();
if (read_cache() < 0)
die("unable to read index file");
istate = the_index;
istate.cache_tree = another;
cache_tree_update(&istate, WRITE_TREE_DRY_RUN);
- return dump_cache_tree(active_cache_tree, another, "");
+ ret = dump_cache_tree(active_cache_tree, another, "");
+ cache_tree_free(&another);
+
+ return ret;
}
diff --git a/t/helper/test-hash.c b/t/helper/test-hash.c
index 261c545..5860dab 100644
--- a/t/helper/test-hash.c
+++ b/t/helper/test-hash.c
@@ -54,5 +54,6 @@ int cmd_hash_impl(int ac, const char **av, int algo)
fwrite(hash, 1, algop->rawsz, stdout);
else
puts(hash_to_hex_algop(hash, algop));
+ free(buffer);
return 0;
}
diff --git a/t/helper/test-json-writer.c b/t/helper/test-json-writer.c
index 37c4525..8c3edac 100644
--- a/t/helper/test-json-writer.c
+++ b/t/helper/test-json-writer.c
@@ -181,12 +181,18 @@ static struct json_writer nest1 = JSON_WRITER_INIT;
static void make_nest1(int pretty)
{
+ make_obj1(0);
+ make_arr1(0);
+
jw_object_begin(&nest1, pretty);
{
jw_object_sub_jw(&nest1, "obj1", &obj1);
jw_object_sub_jw(&nest1, "arr1", &arr1);
}
jw_end(&nest1);
+
+ jw_release(&obj1);
+ jw_release(&arr1);
}
static char *expect_inline1 =
@@ -313,6 +319,9 @@ static void make_mixed1(int pretty)
jw_object_sub_jw(&mixed1, "arr1", &arr1);
}
jw_end(&mixed1);
+
+ jw_release(&obj1);
+ jw_release(&arr1);
}
static void cmp(const char *test, const struct json_writer *jw, const char *exp)
@@ -325,8 +334,8 @@ static void cmp(const char *test, const struct json_writer *jw, const char *exp)
exit(1);
}
-#define t(v) do { make_##v(0); cmp(#v, &v, expect_##v); } while (0)
-#define p(v) do { make_##v(1); cmp(#v, &v, pretty_##v); } while (0)
+#define t(v) do { make_##v(0); cmp(#v, &v, expect_##v); jw_release(&v); } while (0)
+#define p(v) do { make_##v(1); cmp(#v, &v, pretty_##v); jw_release(&v); } while (0)
/*
* Run some basic regression tests with some known patterns.
@@ -381,7 +390,6 @@ static int unit_tests(void)
/* mixed forms */
t(mixed1);
- jw_init(&mixed1);
p(mixed1);
return 0;
@@ -544,7 +552,7 @@ static int scripted(void)
printf("%s\n", jw.json.buf);
- strbuf_release(&jw.json);
+ jw_release(&jw);
return 0;
}
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c
index 229ed41..d20e1b7 100644
--- a/t/helper/test-path-utils.c
+++ b/t/helper/test-path-utils.c
@@ -296,9 +296,8 @@ int cmd__path_utils(int argc, const char **argv)
if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
char *buf = xmallocz(strlen(argv[2]));
int rv = normalize_path_copy(buf, argv[2]);
- if (rv)
- buf = "++failed++";
- puts(buf);
+ puts(rv ? "++failed++" : buf);
+ free(buf);
return 0;
}
@@ -356,7 +355,10 @@ int cmd__path_utils(int argc, const char **argv)
int nongit_ok;
setup_git_directory_gently(&nongit_ok);
while (argc > 3) {
- puts(prefix_path(prefix, prefix_len, argv[3]));
+ char *pfx = prefix_path(prefix, prefix_len, argv[3]);
+
+ puts(pfx);
+ free(pfx);
argc--;
argv++;
}
@@ -366,6 +368,7 @@ int cmd__path_utils(int argc, const char **argv)
if (argc == 4 && !strcmp(argv[1], "strip_path_suffix")) {
char *prefix = strip_path_suffix(argv[2], argv[3]);
printf("%s\n", prefix ? prefix : "(null)");
+ free(prefix);
return 0;
}
diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c
index 9646d85..4d18bfb 100644
--- a/t/helper/test-ref-store.c
+++ b/t/helper/test-ref-store.c
@@ -96,6 +96,7 @@ static const char **get_store(const char **argv, struct ref_store **refs)
die("no such worktree: %s", gitdir);
*refs = get_worktree_ref_store(*p);
+ free_worktrees(worktrees);
} else
die("unknown backend %s", argv[0]);
diff --git a/t/helper/test-regex.c b/t/helper/test-regex.c
index d6f28ca..bd871a7 100644
--- a/t/helper/test-regex.c
+++ b/t/helper/test-regex.c
@@ -34,6 +34,7 @@ static int test_regex_bug(void)
if (m[0].rm_so == 3) /* matches '\n' when it should not */
die("regex bug confirmed: re-build git with NO_REGEX=1");
+ regfree(&r);
return 0;
}
@@ -94,18 +95,20 @@ int cmd__regex(int argc, const char **argv)
die("failed regcomp() for pattern '%s' (%s)", pat, errbuf);
}
if (!str)
- return 0;
+ goto cleanup;
ret = regexec(&r, str, 1, m, 0);
if (ret) {
if (silent || ret == REG_NOMATCH)
- return ret;
+ goto cleanup;
regerror(ret, &r, errbuf, sizeof(errbuf));
die("failed regexec() for subject '%s' (%s)", str, errbuf);
}
- return 0;
+cleanup:
+ regfree(&r);
+ return ret;
usage:
usage("\ttest-tool regex --bug\n"
"\ttest-tool regex [--silent] <pattern>\n"
diff --git a/t/helper/test-scrap-cache-tree.c b/t/helper/test-scrap-cache-tree.c
index 393f160..026c802 100644
--- a/t/helper/test-scrap-cache-tree.c
+++ b/t/helper/test-scrap-cache-tree.c
@@ -12,6 +12,7 @@ int cmd__scrap_cache_tree(int ac, const char **av)
hold_locked_index(&index_lock, LOCK_DIE_ON_ERROR);
if (read_cache() < 0)
die("unable to read index file");
+ cache_tree_free(&active_cache_tree);
active_cache_tree = NULL;
if (write_locked_index(&the_index, &index_lock, COMMIT_LOCK))
die("unable to write index file");
diff --git a/t/helper/test-urlmatch-normalization.c b/t/helper/test-urlmatch-normalization.c
index 8f4d67e..86edd45 100644
--- a/t/helper/test-urlmatch-normalization.c
+++ b/t/helper/test-urlmatch-normalization.c
@@ -5,8 +5,9 @@
int cmd__urlmatch_normalization(int argc, const char **argv)
{
const char usage[] = "test-tool urlmatch-normalization [-p | -l] <url1> | <url1> <url2>";
- char *url1, *url2;
+ char *url1 = NULL, *url2 = NULL;
int opt_p = 0, opt_l = 0;
+ int ret = 0;
/*
* For one url, succeed if url_normalize succeeds on it, fail otherwise.
@@ -39,7 +40,7 @@ int cmd__urlmatch_normalization(int argc, const char **argv)
printf("%s\n", url1);
if (opt_l)
printf("%u\n", (unsigned)info.url_len);
- return 0;
+ goto cleanup;
}
if (opt_p || opt_l)
@@ -47,5 +48,9 @@ int cmd__urlmatch_normalization(int argc, const char **argv)
url1 = url_normalize(argv[1], NULL);
url2 = url_normalize(argv[2], NULL);
- return (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1;
+ ret = (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1;
+cleanup:
+ free(url1);
+ free(url2);
+ return ret;
}
diff --git a/t/t0015-hash.sh b/t/t0015-hash.sh
index 086822f..0a087a1 100755
--- a/t/t0015-hash.sh
+++ b/t/t0015-hash.sh
@@ -1,8 +1,9 @@
#!/bin/sh
test_description='test basic hash implementation'
-. ./test-lib.sh
+TEST_PASSES_SANITIZE_LEAK=true
+. ./test-lib.sh
test_expect_success 'test basic SHA-1 hash values' '
test-tool sha1 </dev/null >actual &&
diff --git a/t/t0019-json-writer.sh b/t/t0019-json-writer.sh
index 3b0c336..19a730c 100755
--- a/t/t0019-json-writer.sh
+++ b/t/t0019-json-writer.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='test json-writer JSON generation'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
test_expect_success 'unit test of json-writer routines' '
diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh
index aa35350..1f2007e 100755
--- a/t/t0060-path-utils.sh
+++ b/t/t0060-path-utils.sh
@@ -5,6 +5,7 @@
test_description='Test various path utilities'
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
norm_path() {
diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index 9067572..d8e2fc4 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -5,6 +5,8 @@ test_description="Test whether cache-tree is properly updated
Tests whether various commands properly update and/or rewrite the
cache-tree extension.
"
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
cmp_cache_tree () {
diff --git a/t/t0095-bloom.sh b/t/t0095-bloom.sh
index 5945973..daeb4a5 100755
--- a/t/t0095-bloom.sh
+++ b/t/t0095-bloom.sh
@@ -67,7 +67,7 @@ test_expect_success 'compute bloom key for test string 2' '
test_cmp expect actual
'
-test_expect_success 'get bloom filters for commit with no changes' '
+test_expect_success !SANITIZE_LEAK 'get bloom filters for commit with no changes' '
git init &&
git commit --allow-empty -m "c0" &&
cat >expect <<-\EOF &&
diff --git a/t/t0110-urlmatch-normalization.sh b/t/t0110-urlmatch-normalization.sh
index 4dc9fec..12d817f 100755
--- a/t/t0110-urlmatch-normalization.sh
+++ b/t/t0110-urlmatch-normalization.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='urlmatch URL normalization'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
# The base name of the test url files
diff --git a/t/t5303-pack-corruption-resilience.sh b/t/t5303-pack-corruption-resilience.sh
index 41e6dc4..2926e8d 100755
--- a/t/t5303-pack-corruption-resilience.sh
+++ b/t/t5303-pack-corruption-resilience.sh
@@ -4,6 +4,8 @@
#
test_description='resilience to pack corruptions with redundant objects'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
# Note: the test objects are created with knowledge of their pack encoding
diff --git a/t/t5308-pack-detect-duplicates.sh b/t/t5308-pack-detect-duplicates.sh
index 693b241..655cafa 100755
--- a/t/t5308-pack-detect-duplicates.sh
+++ b/t/t5308-pack-detect-duplicates.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='handling of duplicate objects in incoming packfiles'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-pack.sh
diff --git a/t/t5309-pack-delta-cycles.sh b/t/t5309-pack-delta-cycles.sh
index 55b7876..4e910c5 100755
--- a/t/t5309-pack-delta-cycles.sh
+++ b/t/t5309-pack-delta-cycles.sh
@@ -1,6 +1,8 @@
#!/bin/sh
test_description='test index-pack handling of delta cycles in packfiles'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-pack.sh
diff --git a/t/t5321-pack-large-objects.sh b/t/t5321-pack-large-objects.sh
index 8a56d98..70770fe 100755
--- a/t/t5321-pack-large-objects.sh
+++ b/t/t5321-pack-large-objects.sh
@@ -6,6 +6,8 @@
test_description='git pack-object with "large" deltas
'
+
+TEST_PASSES_SANITIZE_LEAK=true
. ./test-lib.sh
. "$TEST_DIRECTORY"/lib-pack.sh
diff --git a/t/t7812-grep-icase-non-ascii.sh b/t/t7812-grep-icase-non-ascii.sh
index ac7be54..31c66b6 100755
--- a/t/t7812-grep-icase-non-ascii.sh
+++ b/t/t7812-grep-icase-non-ascii.sh
@@ -2,6 +2,7 @@
test_description='grep icase on non-English locales'
+TEST_PASSES_SANITIZE_LEAK=true
. ./lib-gettext.sh
doalarm () {