From 014239aa577a612d856168cbe8a8e3e0757775cd Mon Sep 17 00:00:00 2001 From: Arpan Sharma Date: Thu, 22 Oct 2026 11:41:28 -0500 Subject: [PATCH] TLS: free the X25519 non-blocking context of a hybrid key share With WC_X25519_NONBLOCK and WOLFSSL_ASYNC_CRYPT_SW, an X25519 key made for a key share with an async device gets a non-blocking context. TLSX_KeyShare_FreeAll() freed it in the X25519 branch but not for the X25519 key of a hybrid key share such as X25519MLKEM768, so it leaked when such a key share was freed with its key still set, for example on the client after a HelloRetryRequest. Free it there as in the X25519 branch. --- src/tls.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/tls.c b/src/tls.c index a0acf532869..9d0ae0acf0f 100644 --- a/src/tls.c +++ b/src/tls.c @@ -9570,6 +9570,14 @@ static void TLSX_KeyShare_FreeAll(KeyShareEntry* list, void* heap) /* Free ECC private key */ if (ecc_group == WOLFSSL_ECC_X25519) { #ifdef HAVE_CURVE25519 + #if defined(WC_X25519_NONBLOCK) && \ + defined(WOLFSSL_ASYNC_CRYPT_SW) + if (current->key != NULL && + ((curve25519_key*)current->key)->nb_ctx != NULL) { + XFREE(((curve25519_key*)current->key)->nb_ctx, heap, + DYNAMIC_TYPE_TMP_BUFFER); + } + #endif wc_curve25519_free((curve25519_key*)current->key); #endif }