From: djm@openbsd.org Date: Mon, 15 Sep 2025 03:00:22 +0000 (+0000) Subject: upstream: memory leaks in unit tests X-Git-Tag: V_10_1_P1~67 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4aa090a3d40dddb07d5ebebc501f6457541a501;p=thirdparty%2Fopenssh-portable.git upstream: memory leaks in unit tests OpenBSD-Regress-ID: af11ac7b8034b99ca324af4dae1ef5cd7700b273 --- diff --git a/regress/unittests/misc/test_expand.c b/regress/unittests/misc/test_expand.c index b72a1e9a8..a8be8d9f4 100644 --- a/regress/unittests/misc/test_expand.c +++ b/regress/unittests/misc/test_expand.c @@ -1,4 +1,4 @@ -/* $OpenBSD: test_expand.c,v 1.3 2021/12/14 21:25:27 deraadt Exp $ */ +/* $OpenBSD: test_expand.c,v 1.4 2025/09/15 03:00:22 djm Exp $ */ /* * Regress test for misc string expansion functions. * @@ -71,17 +71,26 @@ test_expand(void) TEST_DONE(); TEST_START("percent_expand"); - ASSERT_STRING_EQ(percent_expand("%%", "%h", "foo", NULL), "%"); - ASSERT_STRING_EQ(percent_expand("%h", "h", "foo", NULL), "foo"); - ASSERT_STRING_EQ(percent_expand("%h ", "h", "foo", NULL), "foo "); - ASSERT_STRING_EQ(percent_expand(" %h", "h", "foo", NULL), " foo"); - ASSERT_STRING_EQ(percent_expand(" %h ", "h", "foo", NULL), " foo "); - ASSERT_STRING_EQ(percent_expand(" %a%b ", "a", "foo", "b", "bar", NULL), - " foobar "); +#define CHECK_ONE(val, expect) \ + ASSERT_STRING_EQ(val, expect); \ + free(val); + ret = percent_expand("%%", "%h", "foo", NULL); + CHECK_ONE(ret, "%"); + ret = percent_expand("%h", "h", "foo", NULL); + CHECK_ONE(ret, "foo"); + ret = percent_expand("%h ", "h", "foo", NULL); + CHECK_ONE(ret, "foo "); + ret = percent_expand(" %h", "h", "foo", NULL); + CHECK_ONE(ret, " foo"); + ret = percent_expand(" %h ", "h", "foo", NULL); + CHECK_ONE(ret, " foo "); + ret = percent_expand(" %a%b ", "a", "foo", "b", "bar", NULL); + CHECK_ONE(ret, " foobar "); TEST_DONE(); TEST_START("percent_dollar_expand"); - ASSERT_STRING_EQ(percent_dollar_expand("%h${FOO}", "h", "foo", NULL), - "foobar"); + ret = percent_dollar_expand("%h${FOO}", "h", "foo", NULL); + CHECK_ONE(ret, "foobar"); +#undef CHECK_ONE TEST_DONE(); } diff --git a/regress/unittests/sshbuf/test_sshbuf_getput_basic.c b/regress/unittests/sshbuf/test_sshbuf_getput_basic.c index 058bf17d4..bfe61a877 100644 --- a/regress/unittests/sshbuf/test_sshbuf_getput_basic.c +++ b/regress/unittests/sshbuf/test_sshbuf_getput_basic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: test_sshbuf_getput_basic.c,v 1.4 2025/06/13 07:35:14 dtucker Exp $ */ +/* $OpenBSD: test_sshbuf_getput_basic.c,v 1.5 2025/09/15 03:00:22 djm Exp $ */ /* * Regress test for sshbuf.h buffer API * @@ -609,6 +609,7 @@ sshbuf_getput_basic_tests(void) ASSERT_PTR_NE(s2, NULL); ASSERT_STRING_EQ(s2, "00000000000000000000"); sshbuf_free(p1); + free(s2); TEST_DONE(); TEST_START("sshbuf_poke_u16"); @@ -643,6 +644,7 @@ sshbuf_getput_basic_tests(void) ASSERT_PTR_NE(s2, NULL); ASSERT_STRING_EQ(s2, "00000000000000000000"); sshbuf_free(p1); + free(s2); TEST_DONE(); TEST_START("sshbuf_poke_u8"); @@ -673,6 +675,7 @@ sshbuf_getput_basic_tests(void) ASSERT_PTR_NE(s2, NULL); ASSERT_STRING_EQ(s2, "00000000000000000000"); sshbuf_free(p1); + free(s2); TEST_DONE(); TEST_START("sshbuf_poke"); @@ -707,5 +710,6 @@ sshbuf_getput_basic_tests(void) ASSERT_PTR_NE(s2, NULL); ASSERT_STRING_EQ(s2, "00000000000000000000"); sshbuf_free(p1); + free(s2); TEST_DONE(); } diff --git a/regress/unittests/sshbuf/test_sshbuf_misc.c b/regress/unittests/sshbuf/test_sshbuf_misc.c index 58f55eee8..6b5b380d8 100644 --- a/regress/unittests/sshbuf/test_sshbuf_misc.c +++ b/regress/unittests/sshbuf/test_sshbuf_misc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: test_sshbuf_misc.c,v 1.6 2025/09/04 00:37:10 djm Exp $ */ +/* $OpenBSD: test_sshbuf_misc.c,v 1.7 2025/09/15 03:00:22 djm Exp $ */ /* * Regress test for sshbuf.h buffer API * @@ -214,6 +214,7 @@ test_sshbuf_cmp(void) ASSERT_INT_EQ(sshbuf_cmp(p1, 1000, "silence", 7), SSH_ERR_MESSAGE_INCOMPLETE); ASSERT_INT_EQ(sshbuf_cmp(p1, 0, msg, sizeof(msg) - 1), 0); + sshbuf_free(p1); TEST_DONE(); } @@ -252,6 +253,7 @@ test_sshbuf_find(void) SSH_ERR_MESSAGE_INCOMPLETE); ASSERT_INT_EQ(sshbuf_find(p1, 0, msg + 1, sizeof(msg) - 2, &sz), 0); ASSERT_SIZE_T_EQ(sz, 1); + sshbuf_free(p1); TEST_DONE(); }