From f5f641ff85e983bd87d47eddb1281587373b112b Mon Sep 17 00:00:00 2001 From: Martin Baulig Date: Tue, 25 Oct 2016 15:42:08 +0200 Subject: [PATCH] [BTLS]: Fix a ref-counting leak in X509ChainImplBtls. Fixes #45687. (#3811) * [BTLS]: Fix a ref-counting leak in X509ChainImplBtls. Fixes #45687. * Set 'untrusted = null' in Dispose(). (cherry picked from commit c9a67ffc5addabe74015f7d8f33977f4ab416075) --- mcs/class/System/Mono.Btls/X509ChainImplBtls.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mcs/class/System/Mono.Btls/X509ChainImplBtls.cs b/mcs/class/System/Mono.Btls/X509ChainImplBtls.cs index 79a985ce674..c75bec311ef 100644 --- a/mcs/class/System/Mono.Btls/X509ChainImplBtls.cs +++ b/mcs/class/System/Mono.Btls/X509ChainImplBtls.cs @@ -62,7 +62,7 @@ namespace Mono.Btls untrusted = new X509Certificate2Collection (); policy.ExtraStore = untrusted; for (int i = 0; i < untrustedChain.Count; i++) { - using (var cert = untrustedChain.GetCertificate (i)) + var cert = untrustedChain.GetCertificate (i); using (var impl = new X509CertificateImplBtls (cert)) untrusted.Add (new X509Certificate2 (impl)); } @@ -109,8 +109,8 @@ namespace Mono.Btls for (int i = 0; i < certificates.Length; i++) { var cert = chain.GetCertificate (i); - var impl = new X509CertificateImplBtls (cert); - certificates [i] = new X509Certificate2 (impl); + using (var impl = new X509CertificateImplBtls (cert)) + certificates [i] = new X509Certificate2 (impl); elements.Add (certificates [i]); } @@ -163,6 +163,12 @@ namespace Mono.Btls if (untrusted != null) { foreach (var cert in untrusted) cert.Dispose (); + untrusted = null; + } + if (certificates != null) { + foreach (var cert in certificates) + cert.Dispose (); + certificates = null; } } base.Dispose (disposing); -- 2.25.1