From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 5/9] test-tool regex: call regfree(), fix memory leaks
Date: Fri, 1 Jul 2022 01:47:05 +0200 [thread overview]
Message-ID: <patch-5.9-fe2a8d898f6-20220630T180129Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-0.9-00000000000-20220630T180129Z-avarab@gmail.com>
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".
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
t/helper/test-regex.c | 40 ++++++++++++++++++++-------------
t/t7812-grep-icase-non-ascii.sh | 1 +
2 files changed, 26 insertions(+), 15 deletions(-)
diff --git a/t/helper/test-regex.c b/t/helper/test-regex.c
index d6f28ca8d14..a37d1f7a546 100644
--- a/t/helper/test-regex.c
+++ b/t/helper/test-regex.c
@@ -24,27 +24,35 @@ static int test_regex_bug(void)
char *str = "={}\nfred";
regex_t r;
regmatch_t m[1];
+ int err = 0;
if (regcomp(&r, pat, REG_EXTENDED | REG_NEWLINE))
die("failed regcomp() for pattern '%s'", pat);
- if (regexec(&r, str, 1, m, 0))
- die("no match of pattern '%s' to string '%s'", pat, str);
+ if (regexec(&r, str, 1, m, 0)) {
+ err = error("no match of pattern '%s' to string '%s'", pat, str);
+ goto cleanup;
+ }
/* http://sourceware.org/bugzilla/show_bug.cgi?id=3957 */
- if (m[0].rm_so == 3) /* matches '\n' when it should not */
- die("regex bug confirmed: re-build git with NO_REGEX=1");
+ if (m[0].rm_so == 3) { /* matches '\n' when it should not */
+ err = error("regex bug confirmed: re-build git with NO_REGEX=1");
+ goto cleanup;
+ }
- return 0;
+cleanup:
+ regfree(&r);
+ return err < 0 ? 1 : 0;
}
int cmd__regex(int argc, const char **argv)
{
const char *pat;
const char *str;
- int ret, silent = 0, flags = 0;
+ int silent = 0, flags = 0;
regex_t r;
regmatch_t m[1];
char errbuf[64];
+ int ret = 0;
argv++;
argc--;
@@ -85,27 +93,29 @@ int cmd__regex(int argc, const char **argv)
}
git_setup_gettext();
- ret = regcomp(&r, pat, flags);
- if (ret) {
+ if (regcomp(&r, pat, flags)) {
if (silent)
- return ret;
+ return 1;
regerror(ret, &r, errbuf, sizeof(errbuf));
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 (regexec(&r, str, 1, m, 0)) {
+ ret = 1;
if (silent || ret == REG_NOMATCH)
- return ret;
+ goto cleanup;
regerror(ret, &r, errbuf, sizeof(errbuf));
- die("failed regexec() for subject '%s' (%s)", str, errbuf);
+ error("failed regexec() for subject '%s' (%s)", str, errbuf);
+ goto cleanup;
}
- return 0;
+cleanup:
+ regfree(&r);
+ return ret;
usage:
usage("\ttest-tool regex --bug\n"
"\ttest-tool regex [--silent] <pattern>\n"
diff --git a/t/t7812-grep-icase-non-ascii.sh b/t/t7812-grep-icase-non-ascii.sh
index ac7be547145..31c66b63c2c 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 () {
--
2.37.0.874.g7d3439f13c4
next prev parent reply other threads:[~2022-06-30 23:47 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-30 23:47 [PATCH 0/9] test-tool: fix memory leaks Ævar Arnfjörð Bjarmason
2022-06-30 23:47 ` [PATCH 1/9] test-tool test-hash: fix a memory leak Ævar Arnfjörð Bjarmason
2022-06-30 23:47 ` [PATCH 2/9] test-tool path-utils: " Ævar Arnfjörð Bjarmason
2022-07-01 4:27 ` Eric Sunshine
2022-07-01 9:24 ` Ævar Arnfjörð Bjarmason
2022-06-30 23:47 ` [PATCH 3/9] test-tool {dump,scrap}-cache-tree: fix memory leaks Ævar Arnfjörð Bjarmason
2022-06-30 23:47 ` [PATCH 4/9] test-tool urlmatch-normalization: fix a memory leak Ævar Arnfjörð Bjarmason
2022-06-30 23:47 ` Ævar Arnfjörð Bjarmason [this message]
2022-07-01 2:17 ` [PATCH 5/9] test-tool regex: call regfree(), fix memory leaks Junio C Hamano
2022-06-30 23:47 ` [PATCH 6/9] test-tool json-writer: " Ævar Arnfjörð Bjarmason
2022-06-30 23:47 ` [PATCH 7/9] test-tool bloom: fix a memory leak Ævar Arnfjörð Bjarmason
2022-07-01 4:34 ` Eric Sunshine
2022-07-01 9:25 ` Ævar Arnfjörð Bjarmason
2022-06-30 23:47 ` [PATCH 8/9] test-tool ref-store: " Ævar Arnfjörð Bjarmason
2022-06-30 23:47 ` [PATCH 9/9] test-tool delta: " Ævar Arnfjörð Bjarmason
2022-07-01 10:37 ` [PATCH v2 0/9] test-tool: fix memory leaks Ævar Arnfjörð Bjarmason
2022-07-01 10:37 ` [PATCH v2 1/9] test-tool test-hash: fix a memory leak Ævar Arnfjörð Bjarmason
2022-07-01 10:37 ` [PATCH v2 2/9] test-tool path-utils: " Ævar Arnfjörð Bjarmason
2022-07-01 20:43 ` Junio C Hamano
2022-07-01 10:37 ` [PATCH v2 3/9] test-tool {dump,scrap}-cache-tree: fix memory leaks Ævar Arnfjörð Bjarmason
2022-07-01 10:37 ` [PATCH v2 4/9] test-tool urlmatch-normalization: fix a memory leak Ævar Arnfjörð Bjarmason
2022-07-01 10:37 ` [PATCH v2 5/9] test-tool regex: call regfree(), fix memory leaks Ævar Arnfjörð Bjarmason
2022-07-01 10:37 ` [PATCH v2 6/9] test-tool json-writer: " Ævar Arnfjörð Bjarmason
2022-07-01 10:37 ` [PATCH v2 7/9] test-tool bloom: " Ævar Arnfjörð Bjarmason
2022-07-01 10:37 ` [PATCH v2 8/9] test-tool ref-store: fix a memory leak Ævar Arnfjörð Bjarmason
2022-07-01 10:37 ` [PATCH v2 9/9] test-tool delta: " Ævar Arnfjörð Bjarmason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=patch-5.9-fe2a8d898f6-20220630T180129Z-avarab@gmail.com \
--to=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).