git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 5/9] test-tool regex: call regfree(), fix memory leaks
Date: Thu, 30 Jun 2022 19:17:47 -0700	[thread overview]
Message-ID: <xmqq8rpda850.fsf@gitster.g> (raw)
In-Reply-To: <patch-5.9-fe2a8d898f6-20220630T180129Z-avarab@gmail.com> ("Ævar	Arnfjörð Bjarmason"'s message of "Fri, 1 Jul 2022 01:47:05 +0200")

Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> 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;
> +	}

Hmph.  Does it count as leaking to die() while r is still on the
stack?  I do not mind cleaning everything up thoroughly, but I am
curious if this is really necessary.  Apparently it is, as can be
seen in the patch to t/t7812-grep-icase-non-ascii.sh that allows
us to say "PASSES" with this patch.

> @@ -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;

Ahh, OK, this one does not bother with regfree() at all.  The
changes to the other one may be irrelevant but the changes to this
function would be necessary to mark the test with "PASSES".

> -	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 () {

  reply	other threads:[~2022-07-01  2:20 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 ` [PATCH 5/9] test-tool regex: call regfree(), fix memory leaks Ævar Arnfjörð Bjarmason
2022-07-01  2:17   ` Junio C Hamano [this message]
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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq8rpda850.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).