test-tool regex: call regfree(), fix memory leaks
Fix memory leaks in "test-tool regex" which have been there since c91841594c2 (test-regex: Add a test to check for a bug in the regex routines, 2012-09-01), as a result we can mark a test as passing with SANITIZE=leak using "TEST_PASSES_SANITIZE_LEAK=true". We could regfree() on the die() paths here, which would make some invocations of valgrind(1) happy, but let's just target SANITIZE=leak for now. Variables that are still reachable when we die() are not reported as leaks. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Jul 1, 2022 at 12:37 UTC
a20b0dc796c1fd8998ba81c985261a376c866c9b
2 files changed
+7
-3
t/helper/test-regex.c
+6
-3
@@ -34,6 +34,7 @@ static int test_regex_bug(void)
34
if (m[0].rm_so == 3) /* matches '\n' when it should not */
35
die("regex bug confirmed: re-build git with NO_REGEX=1");
36
37
+ regfree(&r);
38
return 0;
39
}
40
@@ -94,18 +95,20 @@ int cmd__regex(int argc, const char **argv)
95
die("failed regcomp() for pattern '%s' (%s)", pat, errbuf);
96
}
97
if (!str)
97
- return 0;
98
+ goto cleanup;
99
100
ret = regexec(&r, str, 1, m, 0);
101
if (ret) {
102
if (silent || ret == REG_NOMATCH)
102
- return ret;
103
+ goto cleanup;
104
105
regerror(ret, &r, errbuf, sizeof(errbuf));
106
die("failed regexec() for subject '%s' (%s)", str, errbuf);
107
}
108
108
- return 0;
109
+cleanup:
110
+ regfree(&r);
111
+ return ret;
112
usage:
113
usage("\ttest-tool regex --bug\n"
114
"\ttest-tool regex [--silent] <pattern>\n"
t/t7812-grep-icase-non-ascii.sh
+1
@@ -2,6 +2,7 @@
2
3
test_description='grep icase on non-English locales'
4
5
+TEST_PASSES_SANITIZE_LEAK=true
6
. ./lib-gettext.sh
7
8
doalarm () {