diff options
author | Kevin Jones <kevin@vcsjones.com> | 2022-09-29 04:59:00 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-29 04:59:00 +0300 |
commit | b631a675329428c19992b695dc6081c5654fa877 (patch) | |
tree | 8aa23bbf9174629dd638fc823be75baf8347be63 /src/libraries | |
parent | e3ed6c1c26d7d09e10253fd8f90e06e503ae1c61 (diff) |
Dispose of key when importing X.509 certificate from PEM
Diffstat (limited to 'src/libraries')
-rw-r--r-- | src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509Certificate2.cs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509Certificate2.cs b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509Certificate2.cs index 422c29c10e8..b2855084370 100644 --- a/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509Certificate2.cs +++ b/src/libraries/System.Security.Cryptography/src/System/Security/Cryptography/X509Certificates/X509Certificate2.cs @@ -1433,16 +1433,18 @@ namespace System.Security.Cryptography.X509Certificates { if (label.SequenceEqual(eligibleLabel)) { - TAlg key = factory(); - key.ImportFromPem(contents[fields.Location]); - - try - { - return import(key); - } - catch (ArgumentException ae) + using (TAlg key = factory()) { - throw new CryptographicException(SR.Cryptography_X509_NoOrMismatchedPemKey, ae); + key.ImportFromPem(contents[fields.Location]); + + try + { + return import(key); + } + catch (ArgumentException ae) + { + throw new CryptographicException(SR.Cryptography_X509_NoOrMismatchedPemKey, ae); + } } } } |