Skip to content

Commit a20b0dc

Browse files
avargitster
authored andcommitted
test-tool regex: call regfree(), fix memory leaks
Fix memory leaks in "test-tool regex" which have been there since c918415 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1c343e5 commit a20b0dc

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

t/helper/test-regex.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ static int test_regex_bug(void)
3434
if (m[0].rm_so == 3) /* matches '\n' when it should not */
3535
die("regex bug confirmed: re-build git with NO_REGEX=1");
3636

37+
regfree(&r);
3738
return 0;
3839
}
3940

@@ -94,18 +95,20 @@ int cmd__regex(int argc, const char **argv)
9495
die("failed regcomp() for pattern '%s' (%s)", pat, errbuf);
9596
}
9697
if (!str)
97-
return 0;
98+
goto cleanup;
9899

99100
ret = regexec(&r, str, 1, m, 0);
100101
if (ret) {
101102
if (silent || ret == REG_NOMATCH)
102-
return ret;
103+
goto cleanup;
103104

104105
regerror(ret, &r, errbuf, sizeof(errbuf));
105106
die("failed regexec() for subject '%s' (%s)", str, errbuf);
106107
}
107108

108-
return 0;
109+
cleanup:
110+
regfree(&r);
111+
return ret;
109112
usage:
110113
usage("\ttest-tool regex --bug\n"
111114
"\ttest-tool regex [--silent] <pattern>\n"

t/t7812-grep-icase-non-ascii.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='grep icase on non-English locales'
44

5+
TEST_PASSES_SANITIZE_LEAK=true
56
. ./lib-gettext.sh
67

78
doalarm () {

0 commit comments

Comments
 (0)