Commit 976c6ff3 authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

crypt32: Correct reference counting when deleting contexts from collections.

parent 92324ab3
......@@ -255,11 +255,19 @@ static BOOL CRYPT_CollectionDeleteCert(PWINECRYPT_CERTSTORE store,
void *pCertContext)
{
BOOL ret;
PCCERT_CONTEXT linked;
TRACE("(%p, %p)\n", store, pCertContext);
ret = CertDeleteCertificateFromStore(
Context_GetLinkedContext(pCertContext, sizeof(CERT_CONTEXT)));
/* Deleting the linked context results in its ref count getting
* decreased, but the caller of this (CertDeleteCertificateFromStore) also
* decreases pCertContext's ref count, by calling
* CertFreeCertificateContext. Increase ref count of linked context to
* compensate.
*/
linked = Context_GetLinkedContext(pCertContext, sizeof(CERT_CONTEXT));
CertDuplicateCertificateContext(linked);
ret = CertDeleteCertificateFromStore(linked);
return ret;
}
......@@ -333,11 +341,18 @@ static BOOL CRYPT_CollectionDeleteCRL(PWINECRYPT_CERTSTORE store,
void *pCrlContext)
{
BOOL ret;
PCCRL_CONTEXT linked;
TRACE("(%p, %p)\n", store, pCrlContext);
ret = CertDeleteCRLFromStore(
Context_GetLinkedContext(pCrlContext, sizeof(CRL_CONTEXT)));
/* Deleting the linked context results in its ref count getting
* decreased, but the caller of this (CertDeleteCRLFromStore) also
* decreases pCrlContext's ref count, by calling CertFreeCRLContext.
* Increase ref count of linked context to compensate.
*/
linked = Context_GetLinkedContext(pCrlContext, sizeof(CRL_CONTEXT));
CertDuplicateCRLContext(linked);
ret = CertDeleteCRLFromStore(linked);
return ret;
}
......@@ -411,11 +426,18 @@ static BOOL CRYPT_CollectionDeleteCTL(PWINECRYPT_CERTSTORE store,
void *pCtlContext)
{
BOOL ret;
PCCTL_CONTEXT linked;
TRACE("(%p, %p)\n", store, pCtlContext);
ret = CertDeleteCTLFromStore(
Context_GetLinkedContext(pCtlContext, sizeof(CTL_CONTEXT)));
/* Deleting the linked context results in its ref count getting
* decreased, but the caller of this (CertDeleteCTLFromStore) also
* decreases pCtlContext's ref count, by calling CertFreeCTLContext.
* Increase ref count of linked context to compensate.
*/
linked = Context_GetLinkedContext(pCtlContext, sizeof(CTL_CONTEXT));
CertDuplicateCTLContext(linked);
ret = CertDeleteCTLFromStore(linked);
return ret;
}
......
......@@ -574,6 +574,28 @@ static void testCollectionStore(void)
CertCloseStore(collection, 0);
CertCloseStore(store2, 0);
CertCloseStore(store1, 0);
/* Test adding certificates to and deleting certificates from collections.
*/
store1 = CertOpenSystemStoreA(0, "My");
collection = CertOpenStore(CERT_STORE_PROV_COLLECTION, 0, 0,
CERT_STORE_CREATE_NEW_FLAG, NULL);
ret = CertAddEncodedCertificateToStore(store1, X509_ASN_ENCODING,
bigCert, sizeof(bigCert), CERT_STORE_ADD_ALWAYS, &context);
ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
CertDeleteCertificateFromStore(context);
CertAddStoreToCollection(collection, store1,
CERT_PHYSICAL_STORE_ADD_ENABLE_FLAG, 0);
ret = CertAddEncodedCertificateToStore(collection, X509_ASN_ENCODING,
bigCert, sizeof(bigCert), CERT_STORE_ADD_ALWAYS, &context);
ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
CertDeleteCertificateFromStore(context);
CertCloseStore(collection, 0);
CertCloseStore(store1, 0);
}
/* Looks for the property with ID propID in the buffer buf. Returns a pointer
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment