Skip to content

Commit 1caaa85

Browse files
avargitster
authored andcommitted
test-tool json-writer: fix memory leaks
Fix memory leaks introduced with these tests in 7545941 (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a20b0dc commit 1caaa85

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

t/helper/test-json-writer.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,18 @@ static struct json_writer nest1 = JSON_WRITER_INIT;
181181

182182
static void make_nest1(int pretty)
183183
{
184+
make_obj1(0);
185+
make_arr1(0);
186+
184187
jw_object_begin(&nest1, pretty);
185188
{
186189
jw_object_sub_jw(&nest1, "obj1", &obj1);
187190
jw_object_sub_jw(&nest1, "arr1", &arr1);
188191
}
189192
jw_end(&nest1);
193+
194+
jw_release(&obj1);
195+
jw_release(&arr1);
190196
}
191197

192198
static char *expect_inline1 =
@@ -313,6 +319,9 @@ static void make_mixed1(int pretty)
313319
jw_object_sub_jw(&mixed1, "arr1", &arr1);
314320
}
315321
jw_end(&mixed1);
322+
323+
jw_release(&obj1);
324+
jw_release(&arr1);
316325
}
317326

318327
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)
325334
exit(1);
326335
}
327336

328-
#define t(v) do { make_##v(0); cmp(#v, &v, expect_##v); } while (0)
329-
#define p(v) do { make_##v(1); cmp(#v, &v, pretty_##v); } while (0)
337+
#define t(v) do { make_##v(0); cmp(#v, &v, expect_##v); jw_release(&v); } while (0)
338+
#define p(v) do { make_##v(1); cmp(#v, &v, pretty_##v); jw_release(&v); } while (0)
330339

331340
/*
332341
* Run some basic regression tests with some known patterns.
@@ -381,7 +390,6 @@ static int unit_tests(void)
381390

382391
/* mixed forms */
383392
t(mixed1);
384-
jw_init(&mixed1);
385393
p(mixed1);
386394

387395
return 0;
@@ -544,7 +552,7 @@ static int scripted(void)
544552

545553
printf("%s\n", jw.json.buf);
546554

547-
strbuf_release(&jw.json);
555+
jw_release(&jw);
548556
return 0;
549557
}
550558

t/t0019-json-writer.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/sh
22

33
test_description='test json-writer JSON generation'
4+
5+
TEST_PASSES_SANITIZE_LEAK=true
46
. ./test-lib.sh
57

68
test_expect_success 'unit test of json-writer routines' '

0 commit comments

Comments
 (0)