From c51d40cfebe793b2e979db0f2d91ac3b136311bb Mon Sep 17 00:00:00 2001 From: Mat Carter Date: Tue, 7 Mar 2023 02:12:30 +0000 Subject: [PATCH] 8303607: SunMSCAPI provider leaks memory and keys Reviewed-by: weijun --- .../windows/native/libsunmscapi/security.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/jdk.crypto.mscapi/windows/native/libsunmscapi/security.cpp b/src/jdk.crypto.mscapi/windows/native/libsunmscapi/security.cpp index 8580d1e7cf7..e2b3b9652fd 100644 --- a/src/jdk.crypto.mscapi/windows/native/libsunmscapi/security.cpp +++ b/src/jdk.crypto.mscapi/windows/native/libsunmscapi/security.cpp @@ -523,7 +523,11 @@ JNIEXPORT void JNICALL Java_sun_security_mscapi_CKeyStore_loadKeysOrCertificateC else { if (bCallerFreeProv == TRUE) { - ::CryptReleaseContext(hCryptProv, NULL); // deprecated + if ((dwKeySpec & CERT_NCRYPT_KEY_SPEC) == CERT_NCRYPT_KEY_SPEC) { + NCryptFreeObject(hCryptProv); + } else { + ::CryptReleaseContext(hCryptProv, NULL); // deprecated + } bCallerFreeProv = FALSE; }