From 9c2bb3d10d1400b8a968f28600a98e87f5e1c8a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Frauenschl=C3=A4ger?= Date: Mon, 9 Mar 2026 11:17:31 +0100 Subject: [PATCH] Fix memory leak in error case within RsaMGF1 --- wolfcrypt/src/rsa.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/wolfcrypt/src/rsa.c b/wolfcrypt/src/rsa.c index d47fa0f437..914a5e3dd0 100644 --- a/wolfcrypt/src/rsa.c +++ b/wolfcrypt/src/rsa.c @@ -985,6 +985,10 @@ static int RsaMGF1(enum wc_HashType hType, byte* seed, word32 seedSz, #endif if (ret != 0) { /* check for if dynamic memory was needed, then free */ +#ifdef WOLFSSL_SMALL_STACK_CACHE + wc_HashFree(hash, hType); + XFREE(hash, heap, DYNAMIC_TYPE_DIGEST); +#endif #if defined(WOLFSSL_SMALL_STACK) && !defined(WOLFSSL_NO_MALLOC) if (tmpF) { XFREE(tmp, heap, DYNAMIC_TYPE_RSA_BUFFER);