]> git.ipfire.org Git - thirdparty/git.git/commitdiff
test-tool regex: call regfree(), fix memory leaks
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Fri, 1 Jul 2022 10:37:36 +0000 (12:37 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 1 Jul 2022 20:38:50 +0000 (13:38 -0700)
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>
t/helper/test-regex.c
t/t7812-grep-icase-non-ascii.sh

index d6f28ca8d148d9c05fa2941b59054840da0b156f..bd871a735b4fbb19ed99e9bfab56f13d138a0567 100644 (file)
@@ -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"
index ac7be5471452a0a8b2123dc39be80caf3520e9db..31c66b63c2cb008979cc64c3f9df203ce5ed1aeb 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='grep icase on non-English locales'
 
+TEST_PASSES_SANITIZE_LEAK=true
 . ./lib-gettext.sh
 
 doalarm () {