schannel_verify: fix a memory leak of cert_context

Closes #19556
This commit is contained in:
x2018 2025-11-17 02:25:57 +08:00 committed by Daniel Stenberg
parent b42f226b94
commit a6c940a752
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2

View file

@ -166,6 +166,7 @@ static CURLcode add_certs_data_to_store(HCERTSTORE trust_store,
cert_blob.pbData = (BYTE *)CURL_UNCONST(begin_cert_ptr);
cert_blob.cbData = cert_size;
/* Caution: CryptQueryObject() is deprecated */
if(!CryptQueryObject(CERT_QUERY_OBJECT_BLOB,
&cert_blob,
CERT_QUERY_CONTENT_FLAG_CERT,
@ -204,7 +205,6 @@ static CURLcode add_certs_data_to_store(HCERTSTORE trust_store,
cert_context,
CERT_STORE_ADD_ALWAYS,
NULL);
CertFreeCertificateContext(cert_context);
if(!add_cert_result) {
char buffer[WINAPI_ERROR_LEN];
failf(data,
@ -220,6 +220,21 @@ static CURLcode add_certs_data_to_store(HCERTSTORE trust_store,
num_certs++;
}
}
switch(actual_content_type) {
case CERT_QUERY_CONTENT_CERT:
case CERT_QUERY_CONTENT_SERIALIZED_CERT:
CertFreeCertificateContext(cert_context);
break;
case CERT_QUERY_CONTENT_CRL:
case CERT_QUERY_CONTENT_SERIALIZED_CRL:
CertFreeCRLContext((PCCRL_CONTEXT)cert_context);
break;
case CERT_QUERY_CONTENT_CTL:
case CERT_QUERY_CONTENT_SERIALIZED_CTL:
CertFreeCTLContext((PCCTL_CONTEXT)cert_context);
break;
}
}
}
}