]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
test/helpers/quictestlib.c: Use goto instead of return to avoid memory leak
authorJiashengJiang <jiasheng@purdue.edu>
Mon, 12 May 2025 13:59:02 +0000 (09:59 -0400)
committerTomas Mraz <tomas@openssl.org>
Fri, 13 Jun 2025 10:29:55 +0000 (12:29 +0200)
When TEST_ptr(*cssl) fails, bdata should be freed to avoid memory leak.

Fixes: a55b689 ("Use reported short conn id len in qtestlib")
Signed-off-by: JiashengJiang <jiasheng@purdue.edu>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27599)

(cherry picked from commit de1e4989d564ea9a6d2960204806a1f3537419ad)

test/helpers/quictestlib.c

index 680606e59d252f8005f46c474847ad51679f3389..3244e3767f755ad0503b00a76ef8dc156ec9645b 100644 (file)
@@ -136,11 +136,6 @@ int qtest_create_quic_objects(OSSL_LIB_CTX *libctx, SSL_CTX *clientctx,
     BIO *tmpbio = NULL;
 
     *qtserv = NULL;
-    if (*cssl == NULL) {
-        *cssl = SSL_new(clientctx);
-        if (!TEST_ptr(*cssl))
-            return 0;
-    }
 
     if (fault != NULL) {
         *fault = OPENSSL_zalloc(sizeof(**fault));
@@ -148,6 +143,12 @@ int qtest_create_quic_objects(OSSL_LIB_CTX *libctx, SSL_CTX *clientctx,
             goto err;
     }
 
+    if (*cssl == NULL) {
+        *cssl = SSL_new(clientctx);
+        if (!TEST_ptr(*cssl))
+            goto err;
+    }
+
 #ifndef OPENSSL_NO_SSL_TRACE
     if ((flags & QTEST_FLAG_CLIENT_TRACE) != 0) {
         tmpbio = BIO_new_fp(stdout, BIO_NOCLOSE);