crypt32: Add return value to Context_Release to allow detecting reference counting errors.

This commit is contained in:
Juan Lang 2009-10-30 15:06:39 -07:00 committed by Alexandre Julliard
parent f4b359942b
commit 40855cae97
5 changed files with 20 additions and 9 deletions

View File

@ -180,12 +180,14 @@ static void CertDataContext_Free(void *context)
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
{
BOOL ret = TRUE;
TRACE("(%p)\n", pCertContext);
if (pCertContext)
Context_Release((void *)pCertContext, sizeof(CERT_CONTEXT),
ret = Context_Release((void *)pCertContext, sizeof(CERT_CONTEXT),
CertDataContext_Free);
return TRUE;
return ret;
}
DWORD WINAPI CertEnumCertificateContextProperties(PCCERT_CONTEXT pCertContext,

View File

@ -135,11 +135,14 @@ PCONTEXT_PROPERTY_LIST Context_GetProperties(const void *context, size_t context
((PDATA_CONTEXT)ptr)->properties : NULL;
}
void Context_Release(void *context, size_t contextSize,
BOOL Context_Release(void *context, size_t contextSize,
ContextFreeFunc dataContextFree)
{
PBASE_CONTEXT base = BASE_CONTEXT_FROM_CONTEXT(context, contextSize);
BOOL ret = TRUE;
if (base->ref <= 0)
return FALSE;
if (InterlockedDecrement(&base->ref) == 0)
{
TRACE("freeing %p\n", context);
@ -153,7 +156,7 @@ void Context_Release(void *context, size_t contextSize,
/* The linked context is of the same type as this, so release
* it as well, using the same offset and data free function.
*/
Context_Release(CONTEXT_FROM_BASE_CONTEXT(
ret = Context_Release(CONTEXT_FROM_BASE_CONTEXT(
((PLINK_CONTEXT)base)->linked, contextSize), contextSize,
dataContextFree);
break;
@ -164,6 +167,7 @@ void Context_Release(void *context, size_t contextSize,
}
else
TRACE("%p's ref count is %d\n", context, base->ref);
return ret;
}
void Context_CopyProperties(const void *to, const void *from,

View File

@ -243,12 +243,14 @@ static void CrlDataContext_Free(void *context)
BOOL WINAPI CertFreeCRLContext( PCCRL_CONTEXT pCrlContext)
{
BOOL ret = TRUE;
TRACE("(%p)\n", pCrlContext);
if (pCrlContext)
Context_Release((void *)pCrlContext, sizeof(CRL_CONTEXT),
ret = Context_Release((void *)pCrlContext, sizeof(CRL_CONTEXT),
CrlDataContext_Free);
return TRUE;
return ret;
}
DWORD WINAPI CertEnumCRLContextProperties(PCCRL_CONTEXT pCRLContext,

View File

@ -346,8 +346,9 @@ typedef void (*ContextFreeFunc)(void *context);
/* Decrements context's ref count. If context is a link context, releases its
* linked context as well.
* If a data context has its ref count reach 0, calls dataContextFree on it.
* Returns FALSE if the reference count is <= 0 when called.
*/
void Context_Release(void *context, size_t contextSize,
BOOL Context_Release(void *context, size_t contextSize,
ContextFreeFunc dataContextFree);
/**

View File

@ -472,12 +472,14 @@ static void CTLDataContext_Free(void *context)
BOOL WINAPI CertFreeCTLContext(PCCTL_CONTEXT pCTLContext)
{
BOOL ret = TRUE;
TRACE("(%p)\n", pCTLContext);
if (pCTLContext)
Context_Release((void *)pCTLContext, sizeof(CTL_CONTEXT),
ret = Context_Release((void *)pCTLContext, sizeof(CTL_CONTEXT),
CTLDataContext_Free);
return TRUE;
return ret;
}
DWORD WINAPI CertEnumCTLContextProperties(PCCTL_CONTEXT pCTLContext,