diff --git a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java index c52ca66b326..46a0cf79442 100644 --- a/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java +++ b/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11KeyStore.java @@ -57,6 +57,7 @@ import java.security.spec.*; import javax.crypto.SecretKey; import javax.crypto.interfaces.*; +import javax.security.auth.DestroyFailedException; import javax.security.auth.x500.X500Principal; import javax.security.auth.login.LoginException; import javax.security.auth.callback.Callback; @@ -454,7 +455,18 @@ final class P11KeyStore extends KeyStoreSpi { } catch (NullPointerException | IllegalArgumentException e) { throw new KeyStoreException(e); } - engineSetEntry(alias, entry, new KeyStore.PasswordProtection(password)); + + KeyStore.PasswordProtection passwordProtection = + new KeyStore.PasswordProtection(password); + try { + engineSetEntry(alias, entry, passwordProtection); + } finally { + try { + passwordProtection.destroy(); + } catch (DestroyFailedException dfe) { + // ignore + } + } } /**