All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH v2 4/9] test-tool urlmatch-normalization: fix a memory leak
Date: Fri,  1 Jul 2022 12:37:35 +0200	[thread overview]
Message-ID: <patch-v2-4.9-3f9f7bbdeb2-20220701T103503Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-v2-0.9-00000000000-20220701T103503Z-avarab@gmail.com>

Fix a memory leak in "test-tool urlmatch-normalization", as a result
we can mark the corresponding 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-urlmatch-normalization.c | 11 ++++++++---
 t/t0110-urlmatch-normalization.sh      |  2 ++
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/t/helper/test-urlmatch-normalization.c b/t/helper/test-urlmatch-normalization.c
index 8f4d67e6469..86edd454f5c 100644
--- a/t/helper/test-urlmatch-normalization.c
+++ b/t/helper/test-urlmatch-normalization.c
@@ -5,8 +5,9 @@
 int cmd__urlmatch_normalization(int argc, const char **argv)
 {
 	const char usage[] = "test-tool urlmatch-normalization [-p | -l] <url1> | <url1> <url2>";
-	char *url1, *url2;
+	char *url1 = NULL, *url2 = NULL;
 	int opt_p = 0, opt_l = 0;
+	int ret = 0;
 
 	/*
 	 * For one url, succeed if url_normalize succeeds on it, fail otherwise.
@@ -39,7 +40,7 @@ int cmd__urlmatch_normalization(int argc, const char **argv)
 			printf("%s\n", url1);
 		if (opt_l)
 			printf("%u\n", (unsigned)info.url_len);
-		return 0;
+		goto cleanup;
 	}
 
 	if (opt_p || opt_l)
@@ -47,5 +48,9 @@ int cmd__urlmatch_normalization(int argc, const char **argv)
 
 	url1 = url_normalize(argv[1], NULL);
 	url2 = url_normalize(argv[2], NULL);
-	return (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1;
+	ret = (url1 && url2 && !strcmp(url1, url2)) ? 0 : 1;
+cleanup:
+	free(url1);
+	free(url2);
+	return ret;
 }
diff --git a/t/t0110-urlmatch-normalization.sh b/t/t0110-urlmatch-normalization.sh
index 4dc9fecf724..12d817fbd34 100755
--- a/t/t0110-urlmatch-normalization.sh
+++ b/t/t0110-urlmatch-normalization.sh
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 test_description='urlmatch URL normalization'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 # The base name of the test url files
-- 
2.37.0.900.g4d0de1cceb2


  parent reply	other threads:[~2022-07-01 10:38 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
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   ` Ævar Arnfjörð Bjarmason [this message]
2022-07-01 10:37   ` [PATCH v2 5/9] test-tool regex: call regfree(), " Æ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-v2-4.9-3f9f7bbdeb2-20220701T103503Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sunshine@sunshineco.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.