Skip to content

Commit 1b2757d

Browse files
committed
Dispose certificate before throwing exception.
This prevents a possible resource leak in the failure path.
1 parent e6687a7 commit 1b2757d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,11 @@ private async Task InitSslAsync(ProtocolCapabilities serverCapabilities, Connect
12211221
var certificate = new X509Certificate2(cs.CertificateFile, cs.CertificatePassword, X509KeyStorageFlags.MachineKeySet);
12221222
if (!certificate.HasPrivateKey)
12231223
{
1224+
#if NET45
1225+
certificate.Reset();
1226+
#else
1227+
certificate.Dispose();
1228+
#endif
12241229
m_logArguments[1] = cs.CertificateFile;
12251230
Log.Error("Session{0} no private key included with CertificateFile '{1}'", m_logArguments);
12261231
throw new MySqlException("CertificateFile does not contain a private key. " +

0 commit comments

Comments
 (0)