From: JiashengJiang Date: Fri, 16 May 2025 13:37:48 +0000 (-0400) Subject: demos/bio/sconnect.c: Free ssl_bio on error to avoid memory leak X-Git-Tag: openssl-3.4.2~59 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d589d702c99dbfdbb8e33a2c2d6f82bc744d86ad;p=thirdparty%2Fopenssl.git demos/bio/sconnect.c: Free ssl_bio on error to avoid memory leak 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 Reviewed-by: Tom Cosgrove Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/27639) (cherry picked from commit 55d8d859797e8229bc499bbc7c3c76821b654682) --- diff --git a/demos/bio/sconnect.c b/demos/bio/sconnect.c index 716abbf4b59..b813fba7474 100644 --- a/demos/bio/sconnect.c +++ b/demos/bio/sconnect.c @@ -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);