quic_txp_test.c: Cleanup use of WPACKET
authorTomas Mraz <tomas@openssl.org>
Fri, 5 May 2023 14:46:42 +0000 (16:46 +0200)
committerHugo Landau <hlandau@openssl.org>
Wed, 17 May 2023 13:04:17 +0000 (14:04 +0100)
Reviewed-by: Hugo Landau <hlandau@openssl.org>
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/20892)

test/quic_txp_test.c

index 1d71721a6cd75d0b807ab37cf84098fc513d8d27..e01156d1564f71e46e9f6f47ceb78997cbd8a042 100644 (file)
@@ -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;
 }