From 21c3a0dd2642b779e87f002455860604bdd91f43 Mon Sep 17 00:00:00 2001 From: Nachel72 Date: Sun, 17 Aug 2025 14:08:38 +0800 Subject: [PATCH] Fix: Add free to avoid memory leak. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed-by: Saša Nedvědický Reviewed-by: Paul Yang Reviewed-by: Tomas Mraz Reviewed-by: Matt Caswell Reviewed-by: Neil Horman (Merged from https://github.com/openssl/openssl/pull/28289) (cherry picked from commit f9afb3a07eb72428b98e3e31384380564a236700) --- demos/bio/saccept.c | 5 ++++- demos/bio/server-arg.c | 5 ++++- demos/bio/server-cmod.c | 5 ++++- demos/bio/server-conf.c | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/demos/bio/saccept.c b/demos/bio/saccept.c index 6da22ea4409..a539e4de313 100644 --- a/demos/bio/saccept.c +++ b/demos/bio/saccept.c @@ -49,7 +49,8 @@ int main(int argc, char *argv[]) { char *port = NULL; BIO *in = NULL; - BIO *ssl_bio, *tmp; + BIO *ssl_bio = NULL; + BIO *tmp; SSL_CTX *ctx; char buf[512]; int ret = EXIT_FAILURE, i; @@ -79,6 +80,7 @@ int main(int argc, char *argv[]) * Basically it means the SSL BIO will be automatically setup */ BIO_set_accept_bios(in, ssl_bio); + ssl_bio = NULL; /* Arrange to leave server loop on interrupt */ sigsetup(); @@ -117,5 +119,6 @@ int main(int argc, char *argv[]) if (ret != EXIT_SUCCESS) ERR_print_errors_fp(stderr); BIO_free(in); + BIO_free_all(ssl_bio); return ret; } diff --git a/demos/bio/server-arg.c b/demos/bio/server-arg.c index 60a87725a9d..166e714078c 100644 --- a/demos/bio/server-arg.c +++ b/demos/bio/server-arg.c @@ -23,7 +23,8 @@ int main(int argc, char *argv[]) { char *port = "*:4433"; - BIO *ssl_bio, *tmp; + BIO *ssl_bio = NULL; + BIO *tmp; SSL_CTX *ctx; SSL_CONF_CTX *cctx; char buf[512]; @@ -105,6 +106,7 @@ int main(int argc, char *argv[]) * Basically it means the SSL BIO will be automatically setup */ BIO_set_accept_bios(in, ssl_bio); + ssl_bio = NULL; again: /* @@ -140,5 +142,6 @@ int main(int argc, char *argv[]) if (ret != EXIT_SUCCESS) ERR_print_errors_fp(stderr); BIO_free(in); + BIO_free_all(ssl_bio); return ret; } diff --git a/demos/bio/server-cmod.c b/demos/bio/server-cmod.c index 3642fbacf6c..cb9cb9dc0c6 100644 --- a/demos/bio/server-cmod.c +++ b/demos/bio/server-cmod.c @@ -24,7 +24,8 @@ int main(int argc, char *argv[]) unsigned char buf[512]; char *port = "*:4433"; BIO *in = NULL; - BIO *ssl_bio, *tmp; + BIO *ssl_bio = NULL; + BIO *tmp; SSL_CTX *ctx; int ret = EXIT_FAILURE, i; @@ -52,6 +53,7 @@ int main(int argc, char *argv[]) * Basically it means the SSL BIO will be automatically setup */ BIO_set_accept_bios(in, ssl_bio); + ssl_bio = NULL; again: /* @@ -90,5 +92,6 @@ int main(int argc, char *argv[]) if (ret != EXIT_SUCCESS) ERR_print_errors_fp(stderr); BIO_free(in); + BIO_free_all(ssl_bio); return ret; } diff --git a/demos/bio/server-conf.c b/demos/bio/server-conf.c index 5e07a15e7bc..7b8bcf6bff7 100644 --- a/demos/bio/server-conf.c +++ b/demos/bio/server-conf.c @@ -25,7 +25,8 @@ int main(int argc, char *argv[]) { char *port = "*:4433"; BIO *in = NULL; - BIO *ssl_bio, *tmp; + BIO *ssl_bio = NULL; + BIO *tmp; SSL_CTX *ctx; SSL_CONF_CTX *cctx = NULL; CONF *conf = NULL; @@ -97,6 +98,7 @@ int main(int argc, char *argv[]) * Basically it means the SSL BIO will be automatically setup */ BIO_set_accept_bios(in, ssl_bio); + ssl_bio = NULL; again: /* @@ -135,5 +137,6 @@ int main(int argc, char *argv[]) if (ret != EXIT_SUCCESS) ERR_print_errors_fp(stderr); BIO_free(in); + BIO_free_all(ssl_bio); return ret; } -- 2.47.3