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>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 6/9] test-tool json-writer: fix memory leaks
Date: Fri,  1 Jul 2022 01:47:06 +0200	[thread overview]
Message-ID: <patch-6.9-97448b9056e-20220630T180129Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-0.9-00000000000-20220630T180129Z-avarab@gmail.com>

Fix memory leaks introduced with these tests in
75459410edd (json_writer: new routines to create JSON data,
2018-07-13), 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-json-writer.c | 16 ++++++++++++----
 t/t0019-json-writer.sh      |  2 ++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/t/helper/test-json-writer.c b/t/helper/test-json-writer.c
index 37c452535f8..8c3edacc000 100644
--- a/t/helper/test-json-writer.c
+++ b/t/helper/test-json-writer.c
@@ -181,12 +181,18 @@ static struct json_writer nest1 = JSON_WRITER_INIT;
 
 static void make_nest1(int pretty)
 {
+	make_obj1(0);
+	make_arr1(0);
+
 	jw_object_begin(&nest1, pretty);
 	{
 		jw_object_sub_jw(&nest1, "obj1", &obj1);
 		jw_object_sub_jw(&nest1, "arr1", &arr1);
 	}
 	jw_end(&nest1);
+
+	jw_release(&obj1);
+	jw_release(&arr1);
 }
 
 static char *expect_inline1 =
@@ -313,6 +319,9 @@ static void make_mixed1(int pretty)
 		jw_object_sub_jw(&mixed1, "arr1", &arr1);
 	}
 	jw_end(&mixed1);
+
+	jw_release(&obj1);
+	jw_release(&arr1);
 }
 
 static void cmp(const char *test, const struct json_writer *jw, const char *exp)
@@ -325,8 +334,8 @@ static void cmp(const char *test, const struct json_writer *jw, const char *exp)
 	exit(1);
 }
 
-#define t(v) do { make_##v(0); cmp(#v, &v, expect_##v); } while (0)
-#define p(v) do { make_##v(1); cmp(#v, &v, pretty_##v); } while (0)
+#define t(v) do { make_##v(0); cmp(#v, &v, expect_##v); jw_release(&v); } while (0)
+#define p(v) do { make_##v(1); cmp(#v, &v, pretty_##v); jw_release(&v); } while (0)
 
 /*
  * Run some basic regression tests with some known patterns.
@@ -381,7 +390,6 @@ static int unit_tests(void)
 
 	/* mixed forms */
 	t(mixed1);
-	jw_init(&mixed1);
 	p(mixed1);
 
 	return 0;
@@ -544,7 +552,7 @@ static int scripted(void)
 
 	printf("%s\n", jw.json.buf);
 
-	strbuf_release(&jw.json);
+	jw_release(&jw);
 	return 0;
 }
 
diff --git a/t/t0019-json-writer.sh b/t/t0019-json-writer.sh
index 3b0c336b38e..19a730c29ed 100755
--- a/t/t0019-json-writer.sh
+++ b/t/t0019-json-writer.sh
@@ -1,6 +1,8 @@
 #!/bin/sh
 
 test_description='test json-writer JSON generation'
+
+TEST_PASSES_SANITIZE_LEAK=true
 . ./test-lib.sh
 
 test_expect_success 'unit test of json-writer routines' '
-- 
2.37.0.874.g7d3439f13c4


  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 ` [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 ` Ævar Arnfjörð Bjarmason [this message]
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-6.9-97448b9056e-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 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.