]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
demos/bio/sconnect.c: Free ssl_bio on error to avoid memory leak
authorJiashengJiang <jiasheng@purdue.edu>
Fri, 16 May 2025 13:37:48 +0000 (09:37 -0400)
committerTomas Mraz <tomas@openssl.org>
Mon, 19 May 2025 14:22:29 +0000 (16:22 +0200)
Call BIO_free() to release ssl_bio if an error occurs before BIO_push(), preventing a memory leak.

Fixes: 396e720965 ("Fix certificate validation for IPv6 literals in sconnect demo")
Signed-off-by: JiashengJiang <jiasheng@purdue.edu>
Reviewed-by: Tom Cosgrove <tom.cosgrove@arm.com>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/27639)

demos/bio/sconnect.c

index b4ad3df14b375d3bdc09b1a495ebefa698489dd6..1f4be4f635ffc7674ca0f8c90fc8519706e58dcc 100644 (file)
@@ -74,8 +74,10 @@ int main(int argc, char *argv[])
 
     /* The BIO has parsed the host:port and even IPv6 literals in [] */
     hostname = BIO_get_conn_hostname(out);
-    if (!hostname || SSL_set1_host(ssl, hostname) <= 0)
+    if (!hostname || SSL_set1_host(ssl, hostname) <= 0) {
+        BIO_free(ssl_bio);
         goto err;
+    }
 
     BIO_set_nbio(out, 1);
     out = BIO_push(ssl_bio, out);