[ssl/win] Always free the X509 certificates after use, fix leak.

R=aam@google.com, asiva@google.com

Bug: https://github.com/dart-lang/sdk/issues/54251
TEST=manually on win
Change-Id: Ia8ce28e69d91606e2b7fe2af8335abd815b0e7d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340720
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Auto-Submit: yami yami <yaminet1024@gmail.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
This commit is contained in:
yamichonghe 2023-12-11 17:49:58 +00:00 committed by Commit Queue
parent 8371eb481f
commit 1ddafec2d3

View file

@ -120,19 +120,19 @@ static bool AddCertificatesFromNamedSystemStore(const wchar_t* name,
}
int status = X509_STORE_add_cert(store, root_cert);
// Always free the certificate after use.
X509_free(root_cert);
if (status == 0) {
int error = ERR_get_error();
if (ERR_GET_REASON(error) == X509_R_CERT_ALREADY_IN_HASH_TABLE) {
if (SSL_LOG_STATUS) {
Syslog::Print("...duplicate\n");
}
X509_free(root_cert);
continue;
}
if (SSL_LOG_STATUS) {
PrintSSLErr("Failed to add certificate to x509 trust store");
}
X509_free(root_cert);
CertFreeCertificateContext(cert_context);
CertCloseStore(cert_store, 0);
return false;