- call CertFreeCertificateContext from CertDeleteCertificateFromStore

- fix some ref counting problems
This commit is contained in:
Juan Lang 2005-09-09 09:09:45 +00:00 committed by Alexandre Julliard
parent 110cfa3428
commit 25cb6e081f
2 changed files with 9 additions and 14 deletions

View File

@ -523,7 +523,6 @@ static BOOL WINAPI CRYPT_MemDeleteCert(HCERTSTORE hCertStore,
*/ */
list_remove(&cert->entry); list_remove(&cert->entry);
cert->entry.prev = cert->entry.next = &store->certs; cert->entry.prev = cert->entry.next = &store->certs;
CertFreeCertificateContext((PCCERT_CONTEXT)cert);
break; break;
} }
} }
@ -784,10 +783,7 @@ static BOOL WINAPI CRYPT_CollectionDeleteCert(HCERTSTORE hCertStore,
ret = CertDeleteCertificateFromStore((PCCERT_CONTEXT)context->childContext); ret = CertDeleteCertificateFromStore((PCCERT_CONTEXT)context->childContext);
if (ret) if (ret)
{
context->childContext = NULL; context->childContext = NULL;
CertFreeCertificateContext((PCCERT_CONTEXT)context);
}
return ret; return ret;
} }
@ -1171,7 +1167,6 @@ static PWINE_CERT_CONTEXT_REF CRYPT_RegEnumCert(PWINECRYPT_CERTSTORE store,
ret = (PWINE_REG_CERT_CONTEXT)pPrev; ret = (PWINE_REG_CERT_CONTEXT)pPrev;
memcpy(&ret->cert, child, sizeof(WINE_CERT_CONTEXT_REF)); memcpy(&ret->cert, child, sizeof(WINE_CERT_CONTEXT_REF));
ret->cert.cert.hCertStore = (HCERTSTORE)store; ret->cert.cert.hCertStore = (HCERTSTORE)store;
InterlockedIncrement(&ret->cert.context->ref);
ret->childContext = child; ret->childContext = child;
} }
} }
@ -1186,7 +1181,6 @@ static PWINE_CERT_CONTEXT_REF CRYPT_RegEnumCert(PWINECRYPT_CERTSTORE store,
{ {
memcpy(&ret->cert, child, sizeof(WINE_CERT_CONTEXT_REF)); memcpy(&ret->cert, child, sizeof(WINE_CERT_CONTEXT_REF));
ret->cert.cert.hCertStore = (HCERTSTORE)store; ret->cert.cert.hCertStore = (HCERTSTORE)store;
InterlockedIncrement(&ret->cert.context->ref);
ret->childContext = child; ret->childContext = child;
} }
else else
@ -2327,7 +2321,10 @@ BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
if (!pCertContext) if (!pCertContext)
ret = TRUE; ret = TRUE;
else if (!pCertContext->hCertStore) else if (!pCertContext->hCertStore)
{
ret = TRUE; ret = TRUE;
CertFreeCertificateContext(pCertContext);
}
else else
{ {
PWINECRYPT_CERTSTORE hcs = PWINECRYPT_CERTSTORE hcs =
@ -2338,7 +2335,10 @@ BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext)
else if (hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC) else if (hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC)
ret = FALSE; ret = FALSE;
else else
{
ret = hcs->deleteCert(hcs, pCertContext, 0); ret = hcs->deleteCert(hcs, pCertContext, 0);
CertFreeCertificateContext(pCertContext);
}
} }
return ret; return ret;
} }
@ -2443,7 +2443,7 @@ BOOL WINAPI CertCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
if (InterlockedDecrement(&hcs->ref) == 0) if (InterlockedDecrement(&hcs->ref) == 0)
{ {
TRACE("freeing %p\n", hcs); TRACE("%p's ref count is 0, freeing\n", hcs);
hcs->dwMagic = 0; hcs->dwMagic = 0;
if (!(hcs->dwOpenFlags & CERT_STORE_NO_CRYPT_RELEASE_FLAG)) if (!(hcs->dwOpenFlags & CERT_STORE_NO_CRYPT_RELEASE_FLAG))
CryptReleaseContext(hcs->cryptProv, 0); CryptReleaseContext(hcs->cryptProv, 0);
@ -2883,12 +2883,11 @@ BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
if (InterlockedDecrement(&ref->context->ref) == 0) if (InterlockedDecrement(&ref->context->ref) == 0)
{ {
TRACE("freeing %p\n", ref->context); TRACE("%p's ref count is 0, freeing\n", ref->context);
CRYPT_FreeCert(ref->context); CRYPT_FreeCert(ref->context);
} }
else else
TRACE("%p's ref count is %ld\n", ref->context, TRACE("%p's ref count is %ld\n", ref->context, ref->context->ref);
ref->context->ref);
if (store && store->dwMagic == WINE_CRYPTCERTSTORE_MAGIC && if (store && store->dwMagic == WINE_CRYPTCERTSTORE_MAGIC &&
store->freeCert) store->freeCert)
store->freeCert(ref); store->freeCert(ref);

View File

@ -166,7 +166,6 @@ static void testMemStore(void)
ret = CertDeleteCertificateFromStore(context); ret = CertDeleteCertificateFromStore(context);
ok(ret, "CertDeleteCertificateFromStore failed: %08lx\n", ok(ret, "CertDeleteCertificateFromStore failed: %08lx\n",
GetLastError()); GetLastError());
CertFreeCertificateContext(context);
} }
/* add a cert to store1 */ /* add a cert to store1 */
ret = CertAddEncodedCertificateToStore(store1, X509_ASN_ENCODING, bigCert, ret = CertAddEncodedCertificateToStore(store1, X509_ASN_ENCODING, bigCert,
@ -727,10 +726,7 @@ static void testRegStore(void)
context = CertEnumCertificatesInStore(store, NULL); context = CertEnumCertificatesInStore(store, NULL);
ok(context != NULL, "Expected a cert context\n"); ok(context != NULL, "Expected a cert context\n");
if (context) if (context)
{
CertDeleteCertificateFromStore(context); CertDeleteCertificateFromStore(context);
CertFreeCertificateContext(context);
}
ret = CertControlStore(store, 0, CERT_STORE_CTRL_COMMIT, NULL); ret = CertControlStore(store, 0, CERT_STORE_CTRL_COMMIT, NULL);
ok(ret, "CertControlStore failed: %08lx\n", GetLastError()); ok(ret, "CertControlStore failed: %08lx\n", GetLastError());