Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Jones <kevin@vcsjones.com>2022-09-29 04:59:00 +0300
committerGitHub <noreply@github.com>2022-09-29 04:59:00 +0300
commitb631a675329428c19992b695dc6081c5654fa877 (patch)
tree8aa23bbf9174629dd638fc823be75baf8347be63 /src/libraries
parente3ed6c1c26d7d09e10253fd8f90e06e503ae1c61 (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.cs20
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);
+ }
}
}
}