Jacek Caban : crypt32: Moved context desatructor to vtbl.
Alexandre Julliard
julliard at winehq.org
Mon Oct 14 12:39:29 CDT 2013
Module: wine
Branch: master
Commit: 993691bef556092d8def4a670f23da58282e3935
URL: http://source.winehq.org/git/wine.git/?a=commit;h=993691bef556092d8def4a670f23da58282e3935
Author: Jacek Caban <jacek at codeweavers.com>
Date: Mon Oct 14 14:47:30 2013 +0200
crypt32: Moved context desatructor to vtbl.
---
dlls/crypt32/cert.c | 24 ++++++++++++++----------
dlls/crypt32/context.c | 10 ++++++----
dlls/crypt32/crl.c | 24 ++++++++++++++----------
dlls/crypt32/crypt32_private.h | 17 +++++++++++------
dlls/crypt32/ctl.c | 28 ++++++++++++++++------------
5 files changed, 61 insertions(+), 42 deletions(-)
diff --git a/dlls/crypt32/cert.c b/dlls/crypt32/cert.c
index 678a44b..9016d8c 100644
--- a/dlls/crypt32/cert.c
+++ b/dlls/crypt32/cert.c
@@ -109,6 +109,18 @@ BOOL WINAPI CertAddEncodedCertificateToSystemStoreW(LPCWSTR pszCertStoreName,
return ret;
}
+static void Cert_free(context_t *context)
+{
+ cert_t *cert = (cert_t*)context;
+
+ CryptMemFree(cert->ctx.pbCertEncoded);
+ LocalFree(cert->ctx.pCertInfo);
+}
+
+static const context_vtbl_t cert_vtbl = {
+ Cert_free
+};
+
BOOL WINAPI CertAddCertificateLinkToStore(HCERTSTORE hCertStore,
PCCERT_CONTEXT pCertContext, DWORD dwAddDisposition,
PCCERT_CONTEXT *ppCertContext)
@@ -154,7 +166,7 @@ PCCERT_CONTEXT WINAPI CertCreateCertificateContext(DWORD dwCertEncodingType,
{
BYTE *data = NULL;
- cert = Context_CreateDataContext(sizeof(CERT_CONTEXT));
+ cert = Context_CreateDataContext(sizeof(CERT_CONTEXT), &cert_vtbl);
if (!cert)
goto end;
data = CryptMemAlloc(cbCertEncoded);
@@ -187,14 +199,6 @@ PCCERT_CONTEXT WINAPI CertDuplicateCertificateContext(PCCERT_CONTEXT pCertContex
return pCertContext;
}
-static void CertDataContext_Free(void *context)
-{
- PCERT_CONTEXT certContext = context;
-
- CryptMemFree(certContext->pbCertEncoded);
- LocalFree(certContext->pCertInfo);
-}
-
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
{
BOOL ret = TRUE;
@@ -202,7 +206,7 @@ BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
TRACE("(%p)\n", pCertContext);
if (pCertContext)
- ret = Context_Release(&cert_from_ptr(pCertContext)->base, CertDataContext_Free);
+ ret = Context_Release(&cert_from_ptr(pCertContext)->base);
return ret;
}
diff --git a/dlls/crypt32/context.c b/dlls/crypt32/context.c
index 2f71c5b..2a44e9a 100644
--- a/dlls/crypt32/context.c
+++ b/dlls/crypt32/context.c
@@ -29,7 +29,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(context);
#define CONTEXT_FROM_BASE_CONTEXT(p) (void*)(p+1)
#define BASE_CONTEXT_FROM_CONTEXT(p) ((BASE_CONTEXT*)(p)-1)
-void *Context_CreateDataContext(size_t contextSize)
+void *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl)
{
BASE_CONTEXT *context;
@@ -37,6 +37,7 @@ void *Context_CreateDataContext(size_t contextSize)
if (!context)
return NULL;
+ context->vtbl = vtbl;
context->ref = 1;
context->linked = NULL;
context->properties = ContextPropertyList_Create();
@@ -62,6 +63,7 @@ void *Context_CreateLinkContext(unsigned int contextSize, void *linked, unsigned
return NULL;
memcpy(CONTEXT_FROM_BASE_CONTEXT(context), linked, contextSize);
+ context->vtbl = BASE_CONTEXT_FROM_CONTEXT(linked)->vtbl;
context->ref = 1;
context->linked = BASE_CONTEXT_FROM_CONTEXT(linked);
if (addRef)
@@ -103,7 +105,7 @@ CONTEXT_PROPERTY_LIST *Context_GetProperties(const void *context)
return ptr->properties;
}
-BOOL Context_Release(context_t *context, ContextFreeFunc dataContextFree)
+BOOL Context_Release(context_t *context)
{
BOOL ret = TRUE;
@@ -118,9 +120,9 @@ BOOL Context_Release(context_t *context, ContextFreeFunc dataContextFree)
if (!context->linked)
{
ContextPropertyList_Free(context->properties);
- dataContextFree(CONTEXT_FROM_BASE_CONTEXT(context));
+ context->vtbl->free(context);
} else {
- Context_Release(context->linked, dataContextFree);
+ Context_Release(context->linked);
}
CryptMemFree(context);
}
diff --git a/dlls/crypt32/crl.c b/dlls/crypt32/crl.c
index fcdec5b..9ecc23f 100644
--- a/dlls/crypt32/crl.c
+++ b/dlls/crypt32/crl.c
@@ -29,6 +29,18 @@
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
+static void CRL_free(context_t *context)
+{
+ crl_t *crl = (crl_t*)context;
+
+ CryptMemFree(crl->ctx.pbCrlEncoded);
+ LocalFree(crl->ctx.pCrlInfo);
+}
+
+static const context_vtbl_t crl_vtbl = {
+ CRL_free
+};
+
PCCRL_CONTEXT WINAPI CertCreateCRLContext(DWORD dwCertEncodingType,
const BYTE* pbCrlEncoded, DWORD cbCrlEncoded)
{
@@ -52,7 +64,7 @@ PCCRL_CONTEXT WINAPI CertCreateCRLContext(DWORD dwCertEncodingType,
{
BYTE *data = NULL;
- crl = Context_CreateDataContext(sizeof(CRL_CONTEXT));
+ crl = Context_CreateDataContext(sizeof(CRL_CONTEXT), &crl_vtbl);
if (!crl)
goto end;
data = CryptMemAlloc(cbCrlEncoded);
@@ -331,14 +343,6 @@ PCCRL_CONTEXT WINAPI CertDuplicateCRLContext(PCCRL_CONTEXT pCrlContext)
return pCrlContext;
}
-static void CrlDataContext_Free(void *context)
-{
- PCRL_CONTEXT crlContext = context;
-
- CryptMemFree(crlContext->pbCrlEncoded);
- LocalFree(crlContext->pCrlInfo);
-}
-
BOOL WINAPI CertFreeCRLContext( PCCRL_CONTEXT pCrlContext)
{
BOOL ret = TRUE;
@@ -346,7 +350,7 @@ BOOL WINAPI CertFreeCRLContext( PCCRL_CONTEXT pCrlContext)
TRACE("(%p)\n", pCrlContext);
if (pCrlContext)
- ret = Context_Release(&crl_from_ptr(pCrlContext)->base, CrlDataContext_Free);
+ ret = Context_Release(&crl_from_ptr(pCrlContext)->base);
return ret;
}
diff --git a/dlls/crypt32/crypt32_private.h b/dlls/crypt32/crypt32_private.h
index 4a4a614..7b64dba 100644
--- a/dlls/crypt32/crypt32_private.h
+++ b/dlls/crypt32/crypt32_private.h
@@ -159,11 +159,18 @@ void default_chain_engine_free(void) DECLSPEC_HIDDEN;
typedef struct _CONTEXT_PROPERTY_LIST CONTEXT_PROPERTY_LIST;
+typedef struct _context_t context_t;
+
+typedef struct {
+ void (*free)(context_t*);
+} context_vtbl_t;
+
typedef struct _context_t {
+ const context_vtbl_t *vtbl;
LONG ref;
struct _context_t *linked;
CONTEXT_PROPERTY_LIST *properties;
-} BASE_CONTEXT, context_t;
+} BASE_CONTEXT;
static inline context_t *context_from_ptr(const void *ptr)
{
@@ -380,7 +387,7 @@ DWORD cert_name_to_str_with_indent(DWORD dwCertEncodingType, DWORD indent,
* which should be one of CERT_CONTEXT, CRL_CONTEXT, or CTL_CONTEXT.
* Free with Context_Release.
*/
-void *Context_CreateDataContext(size_t contextSize) DECLSPEC_HIDDEN;
+void *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl) DECLSPEC_HIDDEN;
/* Creates a new link context with extra bytes. The context refers to linked
* rather than owning its own properties. If addRef is TRUE (which ordinarily
@@ -396,7 +403,7 @@ void *Context_CreateLinkContext(unsigned int contextSize, void *linked, unsigned
void *Context_GetExtra(const void *context, size_t contextSize) DECLSPEC_HIDDEN;
/* Gets the context linked to by context, which must be a link context. */
-void *Context_GetLinkedContext(void *context) DECLSPEC_HIDDEN;
+void *Context_GetLinkedContext(void*) DECLSPEC_HIDDEN;
/* Copies properties from fromContext to toContext. */
void Context_CopyProperties(const void *to, const void *from) DECLSPEC_HIDDEN;
@@ -408,14 +415,12 @@ CONTEXT_PROPERTY_LIST *Context_GetProperties(const void *context) DECLSPEC_HIDDE
void Context_AddRef(context_t*) DECLSPEC_HIDDEN;
-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.
*/
-BOOL Context_Release(context_t *context, ContextFreeFunc dataContextFree) DECLSPEC_HIDDEN;
+BOOL Context_Release(context_t *context) DECLSPEC_HIDDEN;
/**
* Context property list functions
diff --git a/dlls/crypt32/ctl.c b/dlls/crypt32/ctl.c
index 9b5837a..fb976b4 100644
--- a/dlls/crypt32/ctl.c
+++ b/dlls/crypt32/ctl.c
@@ -29,6 +29,20 @@
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
+static void CTL_free(context_t *context)
+{
+ ctl_t *ctl = (ctl_t*)context;
+
+ CryptMsgClose(ctl->ctx.hCryptMsg);
+ CryptMemFree(ctl->ctx.pbCtlEncoded);
+ CryptMemFree(ctl->ctx.pbCtlContext);
+ LocalFree(ctl->ctx.pCtlInfo);
+}
+
+static const context_vtbl_t ctl_vtbl = {
+ CTL_free
+};
+
BOOL WINAPI CertAddCTLContextToStore(HCERTSTORE hCertStore,
PCCTL_CONTEXT pCtlContext, DWORD dwAddDisposition,
PCCTL_CONTEXT* ppStoreContext)
@@ -403,7 +417,7 @@ PCCTL_CONTEXT WINAPI CertCreateCTLContext(DWORD dwMsgAndCertEncodingType,
&ctlInfo, &size);
if (ret)
{
- ctl = Context_CreateDataContext(sizeof(CTL_CONTEXT));
+ ctl = Context_CreateDataContext(sizeof(CTL_CONTEXT), &ctl_vtbl);
if (ctl)
{
BYTE *data = CryptMemAlloc(cbCtlEncoded);
@@ -461,16 +475,6 @@ PCCTL_CONTEXT WINAPI CertDuplicateCTLContext(PCCTL_CONTEXT pCtlContext)
return pCtlContext;
}
-static void CTLDataContext_Free(void *context)
-{
- PCTL_CONTEXT ctlContext = context;
-
- CryptMsgClose(ctlContext->hCryptMsg);
- CryptMemFree(ctlContext->pbCtlEncoded);
- CryptMemFree(ctlContext->pbCtlContext);
- LocalFree(ctlContext->pCtlInfo);
-}
-
BOOL WINAPI CertFreeCTLContext(PCCTL_CONTEXT pCTLContext)
{
BOOL ret = TRUE;
@@ -478,7 +482,7 @@ BOOL WINAPI CertFreeCTLContext(PCCTL_CONTEXT pCTLContext)
TRACE("(%p)\n", pCTLContext);
if (pCTLContext)
- ret = Context_Release(&ctl_from_ptr(pCTLContext)->base, CTLDataContext_Free);
+ ret = Context_Release(&ctl_from_ptr(pCTLContext)->base);
return ret;
}
More information about the wine-cvs
mailing list