Skip to content

Commit a4aa090

Browse files
committed
upstream: memory leaks in unit tests
OpenBSD-Regress-ID: af11ac7b8034b99ca324af4dae1ef5cd7700b273
1 parent 6f59424 commit a4aa090

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

regress/unittests/misc/test_expand.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: test_expand.c,v 1.3 2021/12/14 21:25:27 deraadt Exp $ */
1+
/* $OpenBSD: test_expand.c,v 1.4 2025/09/15 03:00:22 djm Exp $ */
22
/*
33
* Regress test for misc string expansion functions.
44
*
@@ -71,17 +71,26 @@ test_expand(void)
7171
TEST_DONE();
7272

7373
TEST_START("percent_expand");
74-
ASSERT_STRING_EQ(percent_expand("%%", "%h", "foo", NULL), "%");
75-
ASSERT_STRING_EQ(percent_expand("%h", "h", "foo", NULL), "foo");
76-
ASSERT_STRING_EQ(percent_expand("%h ", "h", "foo", NULL), "foo ");
77-
ASSERT_STRING_EQ(percent_expand(" %h", "h", "foo", NULL), " foo");
78-
ASSERT_STRING_EQ(percent_expand(" %h ", "h", "foo", NULL), " foo ");
79-
ASSERT_STRING_EQ(percent_expand(" %a%b ", "a", "foo", "b", "bar", NULL),
80-
" foobar ");
74+
#define CHECK_ONE(val, expect) \
75+
ASSERT_STRING_EQ(val, expect); \
76+
free(val);
77+
ret = percent_expand("%%", "%h", "foo", NULL);
78+
CHECK_ONE(ret, "%");
79+
ret = percent_expand("%h", "h", "foo", NULL);
80+
CHECK_ONE(ret, "foo");
81+
ret = percent_expand("%h ", "h", "foo", NULL);
82+
CHECK_ONE(ret, "foo ");
83+
ret = percent_expand(" %h", "h", "foo", NULL);
84+
CHECK_ONE(ret, " foo");
85+
ret = percent_expand(" %h ", "h", "foo", NULL);
86+
CHECK_ONE(ret, " foo ");
87+
ret = percent_expand(" %a%b ", "a", "foo", "b", "bar", NULL);
88+
CHECK_ONE(ret, " foobar ");
8189
TEST_DONE();
8290

8391
TEST_START("percent_dollar_expand");
84-
ASSERT_STRING_EQ(percent_dollar_expand("%h${FOO}", "h", "foo", NULL),
85-
"foobar");
92+
ret = percent_dollar_expand("%h${FOO}", "h", "foo", NULL);
93+
CHECK_ONE(ret, "foobar");
94+
#undef CHECK_ONE
8695
TEST_DONE();
8796
}

regress/unittests/sshbuf/test_sshbuf_getput_basic.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: test_sshbuf_getput_basic.c,v 1.4 2025/06/13 07:35:14 dtucker Exp $ */
1+
/* $OpenBSD: test_sshbuf_getput_basic.c,v 1.5 2025/09/15 03:00:22 djm Exp $ */
22
/*
33
* Regress test for sshbuf.h buffer API
44
*
@@ -609,6 +609,7 @@ sshbuf_getput_basic_tests(void)
609609
ASSERT_PTR_NE(s2, NULL);
610610
ASSERT_STRING_EQ(s2, "00000000000000000000");
611611
sshbuf_free(p1);
612+
free(s2);
612613
TEST_DONE();
613614

614615
TEST_START("sshbuf_poke_u16");
@@ -643,6 +644,7 @@ sshbuf_getput_basic_tests(void)
643644
ASSERT_PTR_NE(s2, NULL);
644645
ASSERT_STRING_EQ(s2, "00000000000000000000");
645646
sshbuf_free(p1);
647+
free(s2);
646648
TEST_DONE();
647649

648650
TEST_START("sshbuf_poke_u8");
@@ -673,6 +675,7 @@ sshbuf_getput_basic_tests(void)
673675
ASSERT_PTR_NE(s2, NULL);
674676
ASSERT_STRING_EQ(s2, "00000000000000000000");
675677
sshbuf_free(p1);
678+
free(s2);
676679
TEST_DONE();
677680

678681
TEST_START("sshbuf_poke");
@@ -707,5 +710,6 @@ sshbuf_getput_basic_tests(void)
707710
ASSERT_PTR_NE(s2, NULL);
708711
ASSERT_STRING_EQ(s2, "00000000000000000000");
709712
sshbuf_free(p1);
713+
free(s2);
710714
TEST_DONE();
711715
}

regress/unittests/sshbuf/test_sshbuf_misc.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: test_sshbuf_misc.c,v 1.6 2025/09/04 00:37:10 djm Exp $ */
1+
/* $OpenBSD: test_sshbuf_misc.c,v 1.7 2025/09/15 03:00:22 djm Exp $ */
22
/*
33
* Regress test for sshbuf.h buffer API
44
*
@@ -214,6 +214,7 @@ test_sshbuf_cmp(void)
214214
ASSERT_INT_EQ(sshbuf_cmp(p1, 1000, "silence", 7),
215215
SSH_ERR_MESSAGE_INCOMPLETE);
216216
ASSERT_INT_EQ(sshbuf_cmp(p1, 0, msg, sizeof(msg) - 1), 0);
217+
sshbuf_free(p1);
217218
TEST_DONE();
218219
}
219220

@@ -252,6 +253,7 @@ test_sshbuf_find(void)
252253
SSH_ERR_MESSAGE_INCOMPLETE);
253254
ASSERT_INT_EQ(sshbuf_find(p1, 0, msg + 1, sizeof(msg) - 2, &sz), 0);
254255
ASSERT_SIZE_T_EQ(sz, 1);
256+
sshbuf_free(p1);
255257
TEST_DONE();
256258
}
257259

0 commit comments

Comments
 (0)