From dbca844cb3e74b19acf46eb9a2222d30802ad642 Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Fri, 5 May 2023 16:46:42 +0200 Subject: quic_txp_test.c: Cleanup use of WPACKET Reviewed-by: Hugo Landau Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/20892) --- test/quic_txp_test.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/test/quic_txp_test.c b/test/quic_txp_test.c index 1d71721a6c..e01156d156 100644 --- a/test/quic_txp_test.c +++ b/test/quic_txp_test.c @@ -391,7 +391,6 @@ static int schedule_cfq_new_conn_id(struct helper *h) QUIC_CFQ_ITEM *cfq_item; WPACKET wpkt; BUF_MEM *buf_mem = NULL; - char have_wpkt = 0; size_t l = 0; OSSL_QUIC_FRAME_NEW_CONN_ID ncid = {0}; @@ -406,9 +405,12 @@ static int schedule_cfq_new_conn_id(struct helper *h) if (!TEST_true(WPACKET_init(&wpkt, buf_mem))) goto err; - have_wpkt = 1; - if (!TEST_true(ossl_quic_wire_encode_frame_new_conn_id(&wpkt, &ncid))) + if (!TEST_true(ossl_quic_wire_encode_frame_new_conn_id(&wpkt, &ncid))) { + WPACKET_cleanup(&wpkt); goto err; + } + + WPACKET_finish(&wpkt); if (!TEST_true(WPACKET_get_total_written(&wpkt, &l))) goto err; @@ -423,8 +425,8 @@ static int schedule_cfq_new_conn_id(struct helper *h) rc = 1; err: - if (have_wpkt) - WPACKET_cleanup(&wpkt); + if (!rc) + BUF_MEM_free(buf_mem); return rc; } @@ -470,7 +472,6 @@ static int schedule_cfq_new_token(struct helper *h) QUIC_CFQ_ITEM *cfq_item; WPACKET wpkt; BUF_MEM *buf_mem = NULL; - char have_wpkt = 0; size_t l = 0; if (!TEST_ptr(buf_mem = BUF_MEM_new())) @@ -479,10 +480,13 @@ static int schedule_cfq_new_token(struct helper *h) if (!TEST_true(WPACKET_init(&wpkt, buf_mem))) goto err; - have_wpkt = 1; if (!TEST_true(ossl_quic_wire_encode_frame_new_token(&wpkt, token_1, - sizeof(token_1)))) + sizeof(token_1)))) { + WPACKET_cleanup(&wpkt); goto err; + } + + WPACKET_finish(&wpkt); if (!TEST_true(WPACKET_get_total_written(&wpkt, &l))) goto err; @@ -497,8 +501,8 @@ static int schedule_cfq_new_token(struct helper *h) rc = 1; err: - if (have_wpkt) - WPACKET_cleanup(&wpkt); + if (!rc) + BUF_MEM_free(buf_mem); return rc; } -- cgit v1.2.1