From 829c2a022f6929e2a676c5c12a13642a9b9c7dd8 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Fri, 24 Jan 2025 18:32:43 +0100 Subject: [PATCH] Free'ing ctx->srp has to be reference counted as well --- src/internal.c | 11 ++++++++++- src/ssl.c | 10 ---------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/internal.c b/src/internal.c index 666de8645..abfb8c490 100644 --- a/src/internal.c +++ b/src/internal.c @@ -3023,7 +3023,16 @@ void FreeSSL_Ctx(WOLFSSL_CTX* ctx) if (isZero) { WOLFSSL_MSG("CTX ref count down to 0, doing full free"); - +#if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) && \ + !defined(NO_SHA256) && !defined(WC_NO_RNG) + if (ctx->srp != NULL) { + XFREE(ctx->srp_password, ctx->heap, DYNAMIC_TYPE_SRP); + ctx->srp_password = NULL; + wc_SrpTerm(ctx->srp); + XFREE(ctx->srp, ctx->heap, DYNAMIC_TYPE_SRP); + ctx->srp = NULL; + } +#endif SSL_CtxResourceFree(ctx); #if defined(HAVE_SESSION_TICKET) && !defined(NO_WOLFSSL_SERVER) && \ !defined(WOLFSSL_NO_DEF_TICKET_ENC_CB) && !defined(NO_TLS) diff --git a/src/ssl.c b/src/ssl.c index c38fcbf1f..c733173e2 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -1194,16 +1194,6 @@ void wolfSSL_CTX_free(WOLFSSL_CTX* ctx) { WOLFSSL_ENTER("wolfSSL_CTX_free"); if (ctx) { -#if defined(OPENSSL_EXTRA) && defined(WOLFCRYPT_HAVE_SRP) \ -&& !defined(NO_SHA256) && !defined(WC_NO_RNG) - if (ctx->srp != NULL) { - XFREE(ctx->srp_password, ctx->heap, DYNAMIC_TYPE_SRP); - ctx->srp_password = NULL; - wc_SrpTerm(ctx->srp); - XFREE(ctx->srp, ctx->heap, DYNAMIC_TYPE_SRP); - ctx->srp = NULL; - } -#endif FreeSSL_Ctx(ctx); }