From b9ed467425ce2d8dfce2f8beb9f7dc3a50aa8d9c Mon Sep 17 00:00:00 2001 From: Takashi Kojo Date: Sat, 1 Aug 2026 06:45:21 +0900 Subject: [PATCH] Free previous algorithm object when d2i repurposes an EVP_PKEY --- tests/api/test_evp_pkey.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/api/test_evp_pkey.c b/tests/api/test_evp_pkey.c index 93d25dff93..451dd074de 100644 --- a/tests/api/test_evp_pkey.c +++ b/tests/api/test_evp_pkey.c @@ -3105,13 +3105,9 @@ int test_wolfSSL_d2i_PUBKEY_mldsa_reuse(void) if (pkey->pkey.ptr != NULL) { ExpectIntEQ(XMEMCMP(pkey->pkey.ptr, der44, (size_t)der44Sz), 0); } - /* EVP_PKEY_free() releases the per-algorithm object only for the - * final type, so drop the RSA object left from the first decode - * to keep this test leak-free. */ - if (pkey->rsa != NULL && pkey->ownRsa == 1) { - wolfSSL_RSA_free(pkey->rsa); - pkey->rsa = NULL; - } + /* The RSA object from the first decode must have been released + * and detached when the key was repurposed. */ + ExpectNull(wolfSSL_EVP_PKEY_get0_RSA(pkey)); } /* Reuse again with a different ML-DSA level: same type, new key data. */