From: Paul Gofman pgofman@codeweavers.com
--- dlls/crypt32/cert.c | 13 ++++++++++++- dlls/crypt32/tests/cert.c | 6 ++++-- dlls/crypt32/tests/store.c | 6 ++++-- 3 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/dlls/crypt32/cert.c b/dlls/crypt32/cert.c index 7b1edaa2236..75f451435b4 100644 --- a/dlls/crypt32/cert.c +++ b/dlls/crypt32/cert.c @@ -212,6 +212,7 @@ static BOOL add_cert_to_store(WINECRYPT_CERTSTORE *store, const CERT_CONTEXT *ce if (existing) { TRACE("found matching certificate, not adding\n"); + CertFreeCertificateContext(existing); SetLastError(CRYPT_E_EXISTS); return FALSE; } @@ -231,7 +232,9 @@ static BOOL add_cert_to_store(WINECRYPT_CERTSTORE *store, const CERT_CONTEXT *ce { Context_CopyProperties(existing, cert); if (ret_context) - *ret_context = CertDuplicateCertificateContext(existing); + *ret_context = existing; + else + CertFreeCertificateContext(existing); return TRUE; } break; @@ -239,6 +242,7 @@ static BOOL add_cert_to_store(WINECRYPT_CERTSTORE *store, const CERT_CONTEXT *ce if (existing && CompareFileTime(&existing->pCertInfo->NotBefore, &cert->pCertInfo->NotBefore) >= 0) { TRACE("existing certificate is newer, not adding\n"); + CertFreeCertificateContext(existing); SetLastError(CRYPT_E_EXISTS); return FALSE; } @@ -249,6 +253,7 @@ static BOOL add_cert_to_store(WINECRYPT_CERTSTORE *store, const CERT_CONTEXT *ce if (CompareFileTime(&existing->pCertInfo->NotBefore, &cert->pCertInfo->NotBefore) >= 0) { TRACE("existing certificate is newer, not adding\n"); + CertFreeCertificateContext(existing); SetLastError(CRYPT_E_EXISTS); return FALSE; } @@ -267,7 +272,10 @@ static BOOL add_cert_to_store(WINECRYPT_CERTSTORE *store, const CERT_CONTEXT *ce ret = store->vtbl->certs.addContext(store, context_from_ptr(cert), existing ? context_from_ptr(existing) : NULL, (ret_context || inherit_props) ? &new_context : NULL, use_link); if(!ret) + { + CertFreeCertificateContext(existing); return FALSE; + }
if(inherit_props) Context_CopyProperties(context_ptr(new_context), existing); @@ -277,6 +285,9 @@ static BOOL add_cert_to_store(WINECRYPT_CERTSTORE *store, const CERT_CONTEXT *ce else if(new_context) Context_Release(new_context);
+ if (existing) + CertFreeCertificateContext(existing); + TRACE("returning %d\n", ret); return ret; } diff --git a/dlls/crypt32/tests/cert.c b/dlls/crypt32/tests/cert.c index 396f6a2e390..aeab4c02713 100644 --- a/dlls/crypt32/tests/cert.c +++ b/dlls/crypt32/tests/cert.c @@ -275,10 +275,12 @@ static void testAddCert(void) CertFreeCertificateContext(context); }
- CertCloseStore(collection, 0); + ret = CertCloseStore(collection, CERT_CLOSE_STORE_CHECK_FLAG); + ok(ret, "got error %#lx.\n", GetLastError()); }
- CertCloseStore(store, 0); + ret = CertCloseStore(store, CERT_CLOSE_STORE_CHECK_FLAG); + ok(ret, "got error %#lx.\n", GetLastError()); }
static void checkHash(const BYTE *data, DWORD dataLen, ALG_ID algID, diff --git a/dlls/crypt32/tests/store.c b/dlls/crypt32/tests/store.c index 48f06c54f7c..874a920e1d7 100644 --- a/dlls/crypt32/tests/store.c +++ b/dlls/crypt32/tests/store.c @@ -2962,8 +2962,10 @@ static void test_I_UpdateStore(void) certs = countCertsInStore(store1); ok(certs == 0, "Expected 0 certs, got %ld\n", certs);
- CertCloseStore(store1, 0); - CertCloseStore(store2, 0); + ret = CertCloseStore(store1, CERT_CLOSE_STORE_CHECK_FLAG); + ok(ret, "got error %#lx.\n", GetLastError()); + ret = CertCloseStore(store2, CERT_CLOSE_STORE_CHECK_FLAG); + ok(ret, "got error %#lx.\n", GetLastError()); }
static const BYTE pfxdata[] =