Commit 2d6d002b authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

Use CryptMem functions for internal memory allocation.

parent 717a4eb6
...@@ -128,8 +128,8 @@ typedef struct WINE_CRYPTCERTSTORE * (*StoreOpenFunc)(HCRYPTPROV hCryptProv, ...@@ -128,8 +128,8 @@ typedef struct WINE_CRYPTCERTSTORE * (*StoreOpenFunc)(HCRYPTPROV hCryptProv,
struct _WINE_CERT_CONTEXT_REF; struct _WINE_CERT_CONTEXT_REF;
/* Called to enumerate the next certificate in a store. The returned pointer /* Called to enumerate the next certificate in a store. The returned pointer
* must be newly allocated (via HeapAlloc): CertFreeCertificateContext frees * must be newly allocated (via CryptMemAlloc): CertFreeCertificateContext
* it. * frees it.
*/ */
typedef struct _WINE_CERT_CONTEXT_REF * (*EnumCertFunc) typedef struct _WINE_CERT_CONTEXT_REF * (*EnumCertFunc)
(struct WINE_CRYPTCERTSTORE *store, struct _WINE_CERT_CONTEXT_REF *pPrev); (struct WINE_CRYPTCERTSTORE *store, struct _WINE_CERT_CONTEXT_REF *pPrev);
...@@ -353,7 +353,7 @@ static void CRYPT_InitCertRef(PWINE_CERT_CONTEXT_REF ref, ...@@ -353,7 +353,7 @@ static void CRYPT_InitCertRef(PWINE_CERT_CONTEXT_REF ref,
static PWINE_CERT_CONTEXT_REF CRYPT_CreateCertRef(PWINE_CERT_CONTEXT context, static PWINE_CERT_CONTEXT_REF CRYPT_CreateCertRef(PWINE_CERT_CONTEXT context,
HCERTSTORE store) HCERTSTORE store)
{ {
PWINE_CERT_CONTEXT_REF pCertRef = HeapAlloc(GetProcessHeap(), 0, PWINE_CERT_CONTEXT_REF pCertRef = CryptMemAlloc(
sizeof(WINE_CERT_CONTEXT_REF)); sizeof(WINE_CERT_CONTEXT_REF));
if (pCertRef) if (pCertRef)
...@@ -443,7 +443,7 @@ static BOOL WINAPI CRYPT_MemAddCert(HCERTSTORE store, PCCERT_CONTEXT pCert, ...@@ -443,7 +443,7 @@ static BOOL WINAPI CRYPT_MemAddCert(HCERTSTORE store, PCCERT_CONTEXT pCert,
} }
if (add) if (add)
{ {
PWINE_CERT_LIST_ENTRY entry = HeapAlloc(GetProcessHeap(), 0, PWINE_CERT_LIST_ENTRY entry = CryptMemAlloc(
sizeof(WINE_CERT_LIST_ENTRY)); sizeof(WINE_CERT_LIST_ENTRY));
if (entry) if (entry)
...@@ -482,7 +482,7 @@ static PWINE_CERT_CONTEXT_REF CRYPT_MemEnumCert(PWINECRYPT_CERTSTORE store, ...@@ -482,7 +482,7 @@ static PWINE_CERT_CONTEXT_REF CRYPT_MemEnumCert(PWINECRYPT_CERTSTORE store,
listNext = list_next(&ms->certs, &ms->certs); listNext = list_next(&ms->certs, &ms->certs);
if (listNext) if (listNext)
{ {
ret = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_CERT_LIST_ENTRY)); ret = CryptMemAlloc(sizeof(WINE_CERT_LIST_ENTRY));
memcpy(ret, LIST_ENTRY(listNext, WINE_CERT_LIST_ENTRY, entry), memcpy(ret, LIST_ENTRY(listNext, WINE_CERT_LIST_ENTRY, entry),
sizeof(WINE_CERT_LIST_ENTRY)); sizeof(WINE_CERT_LIST_ENTRY));
InterlockedIncrement(&ret->cert.context->ref); InterlockedIncrement(&ret->cert.context->ref);
...@@ -553,7 +553,7 @@ static void WINAPI CRYPT_MemCloseStore(HCERTSTORE hCertStore, DWORD dwFlags) ...@@ -553,7 +553,7 @@ static void WINAPI CRYPT_MemCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
CertFreeCertificateContext((PCCERT_CONTEXT)cert); CertFreeCertificateContext((PCCERT_CONTEXT)cert);
} }
DeleteCriticalSection(&store->cs); DeleteCriticalSection(&store->cs);
HeapFree(GetProcessHeap(), 0, store); CryptMemFree(store);
} }
static WINECRYPT_CERTSTORE *CRYPT_MemOpenStore(HCRYPTPROV hCryptProv, static WINECRYPT_CERTSTORE *CRYPT_MemOpenStore(HCRYPTPROV hCryptProv,
...@@ -570,10 +570,10 @@ static WINECRYPT_CERTSTORE *CRYPT_MemOpenStore(HCRYPTPROV hCryptProv, ...@@ -570,10 +570,10 @@ static WINECRYPT_CERTSTORE *CRYPT_MemOpenStore(HCRYPTPROV hCryptProv,
} }
else else
{ {
store = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, store = CryptMemAlloc(sizeof(WINE_MEMSTORE));
sizeof(WINE_MEMSTORE));
if (store) if (store)
{ {
memset(store, 0, sizeof(WINE_MEMSTORE));
CRYPT_InitStore(&store->hdr, hCryptProv, dwFlags, StoreTypeMem); CRYPT_InitStore(&store->hdr, hCryptProv, dwFlags, StoreTypeMem);
store->hdr.closeStore = CRYPT_MemCloseStore; store->hdr.closeStore = CRYPT_MemCloseStore;
store->hdr.addCert = CRYPT_MemAddCert; store->hdr.addCert = CRYPT_MemAddCert;
...@@ -616,7 +616,7 @@ static BOOL WINAPI CRYPT_CollectionAddCert(HCERTSTORE store, ...@@ -616,7 +616,7 @@ static BOOL WINAPI CRYPT_CollectionAddCert(HCERTSTORE store,
static PWINE_CERT_CONTEXT_REF CRYPT_CollectionCreateCertRef( static PWINE_CERT_CONTEXT_REF CRYPT_CollectionCreateCertRef(
PWINE_CERT_CONTEXT context, HCERTSTORE store) PWINE_CERT_CONTEXT context, HCERTSTORE store)
{ {
PWINE_COLLECTION_CERT_CONTEXT ret = HeapAlloc(GetProcessHeap(), 0, PWINE_COLLECTION_CERT_CONTEXT ret = CryptMemAlloc(
sizeof(WINE_COLLECTION_CERT_CONTEXT)); sizeof(WINE_COLLECTION_CERT_CONTEXT));
if (ret) if (ret)
...@@ -641,10 +641,10 @@ static void WINAPI CRYPT_CollectionCloseStore(HCERTSTORE store, DWORD dwFlags) ...@@ -641,10 +641,10 @@ static void WINAPI CRYPT_CollectionCloseStore(HCERTSTORE store, DWORD dwFlags)
{ {
TRACE("closing %p\n", entry); TRACE("closing %p\n", entry);
CertCloseStore((HCERTSTORE)entry->store, dwFlags); CertCloseStore((HCERTSTORE)entry->store, dwFlags);
HeapFree(GetProcessHeap(), 0, entry); CryptMemFree(entry);
} }
DeleteCriticalSection(&cs->cs); DeleteCriticalSection(&cs->cs);
HeapFree(GetProcessHeap(), 0, cs); CryptMemFree(cs);
} }
/* Advances a collection enumeration by one cert, if possible, where advancing /* Advances a collection enumeration by one cert, if possible, where advancing
...@@ -809,10 +809,10 @@ static WINECRYPT_CERTSTORE *CRYPT_CollectionOpenStore(HCRYPTPROV hCryptProv, ...@@ -809,10 +809,10 @@ static WINECRYPT_CERTSTORE *CRYPT_CollectionOpenStore(HCRYPTPROV hCryptProv,
} }
else else
{ {
store = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, store = CryptMemAlloc(sizeof(WINE_COLLECTIONSTORE));
sizeof(WINE_COLLECTIONSTORE));
if (store) if (store)
{ {
memset(store, 0, sizeof(WINE_COLLECTIONSTORE));
CRYPT_InitStore(&store->hdr, hCryptProv, dwFlags, CRYPT_InitStore(&store->hdr, hCryptProv, dwFlags,
StoreTypeCollection); StoreTypeCollection);
store->hdr.closeStore = CRYPT_CollectionCloseStore; store->hdr.closeStore = CRYPT_CollectionCloseStore;
...@@ -870,7 +870,7 @@ static void CRYPT_RegReadSerializedFromReg(PWINE_REGSTORE store, HKEY key, ...@@ -870,7 +870,7 @@ static void CRYPT_RegReadSerializedFromReg(PWINE_REGSTORE store, HKEY key,
size = 0; size = 0;
rc = RegQueryValueExW(subKey, BlobW, NULL, NULL, NULL, &size); rc = RegQueryValueExW(subKey, BlobW, NULL, NULL, NULL, &size);
if (!rc) if (!rc)
buf = HeapAlloc(GetProcessHeap(), 0, size); buf = CryptMemAlloc(size);
if (buf) if (buf)
{ {
rc = RegQueryValueExW(subKey, BlobW, NULL, NULL, buf, rc = RegQueryValueExW(subKey, BlobW, NULL, NULL, buf,
...@@ -931,7 +931,7 @@ static void CRYPT_RegReadSerializedFromReg(PWINE_REGSTORE store, HKEY key, ...@@ -931,7 +931,7 @@ static void CRYPT_RegReadSerializedFromReg(PWINE_REGSTORE store, HKEY key,
} }
} }
} }
HeapFree(GetProcessHeap(), 0, buf); CryptMemFree(buf);
} }
RegCloseKey(subKey); RegCloseKey(subKey);
} }
...@@ -1012,14 +1012,14 @@ static BOOL CRYPT_SerializeContextsToReg(HKEY key, ...@@ -1012,14 +1012,14 @@ static BOOL CRYPT_SerializeContextsToReg(HKEY key,
ret = contextInterface->serialize(context, 0, NULL, &size); ret = contextInterface->serialize(context, 0, NULL, &size);
if (size) if (size)
buf = HeapAlloc(GetProcessHeap(), 0, size); buf = CryptMemAlloc(size);
if (buf) if (buf)
{ {
ret = contextInterface->serialize(context, 0, buf, &size); ret = contextInterface->serialize(context, 0, buf, &size);
if (ret) if (ret)
ret = CRYPT_WriteSerializedToReg(key, hash, buf, size); ret = CRYPT_WriteSerializedToReg(key, hash, buf, size);
} }
HeapFree(GetProcessHeap(), 0, buf); CryptMemFree(buf);
} }
} }
else else
...@@ -1067,7 +1067,7 @@ static BOOL CRYPT_RegWriteToReg(PWINE_REGSTORE store) ...@@ -1067,7 +1067,7 @@ static BOOL CRYPT_RegWriteToReg(PWINE_REGSTORE store)
ret = FALSE; ret = FALSE;
} }
list_remove(&toDelete->entry); list_remove(&toDelete->entry);
HeapFree(GetProcessHeap(), 0, toDelete); CryptMemFree(toDelete);
} }
LeaveCriticalSection(&store->cs); LeaveCriticalSection(&store->cs);
} }
...@@ -1111,7 +1111,7 @@ static void WINAPI CRYPT_RegCloseStore(HCERTSTORE hCertStore, DWORD dwFlags) ...@@ -1111,7 +1111,7 @@ static void WINAPI CRYPT_RegCloseStore(HCERTSTORE hCertStore, DWORD dwFlags)
store->memStore->closeStore(store->memStore, 0); store->memStore->closeStore(store->memStore, 0);
RegCloseKey(store->key); RegCloseKey(store->key);
DeleteCriticalSection(&store->cs); DeleteCriticalSection(&store->cs);
HeapFree(GetProcessHeap(), 0, store); CryptMemFree(store);
} }
static BOOL WINAPI CRYPT_RegAddCert(HCERTSTORE hCertStore, PCCERT_CONTEXT cert, static BOOL WINAPI CRYPT_RegAddCert(HCERTSTORE hCertStore, PCCERT_CONTEXT cert,
...@@ -1139,7 +1139,7 @@ static BOOL WINAPI CRYPT_RegAddCert(HCERTSTORE hCertStore, PCCERT_CONTEXT cert, ...@@ -1139,7 +1139,7 @@ static BOOL WINAPI CRYPT_RegAddCert(HCERTSTORE hCertStore, PCCERT_CONTEXT cert,
static PWINE_CERT_CONTEXT_REF CRYPT_RegCreateCertRef( static PWINE_CERT_CONTEXT_REF CRYPT_RegCreateCertRef(
PWINE_CERT_CONTEXT context, HCERTSTORE store) PWINE_CERT_CONTEXT context, HCERTSTORE store)
{ {
PWINE_REG_CERT_CONTEXT ret = HeapAlloc(GetProcessHeap(), 0, PWINE_REG_CERT_CONTEXT ret = CryptMemAlloc(
sizeof(WINE_REG_CERT_CONTEXT)); sizeof(WINE_REG_CERT_CONTEXT));
if (ret) if (ret)
...@@ -1175,7 +1175,7 @@ static PWINE_CERT_CONTEXT_REF CRYPT_RegEnumCert(PWINECRYPT_CERTSTORE store, ...@@ -1175,7 +1175,7 @@ static PWINE_CERT_CONTEXT_REF CRYPT_RegEnumCert(PWINECRYPT_CERTSTORE store,
child = rs->memStore->enumCert(rs->memStore, NULL); child = rs->memStore->enumCert(rs->memStore, NULL);
if (child) if (child)
{ {
ret = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_REG_CERT_CONTEXT)); ret = CryptMemAlloc(sizeof(WINE_REG_CERT_CONTEXT));
if (ret) if (ret)
{ {
...@@ -1206,7 +1206,7 @@ static BOOL WINAPI CRYPT_RegDeleteCert(HCERTSTORE hCertStore, ...@@ -1206,7 +1206,7 @@ static BOOL WINAPI CRYPT_RegDeleteCert(HCERTSTORE hCertStore,
else else
{ {
PWINE_HASH_TO_DELETE toDelete = PWINE_HASH_TO_DELETE toDelete =
HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_HASH_TO_DELETE)); CryptMemAlloc(sizeof(WINE_HASH_TO_DELETE));
if (toDelete) if (toDelete)
{ {
...@@ -1224,7 +1224,7 @@ static BOOL WINAPI CRYPT_RegDeleteCert(HCERTSTORE hCertStore, ...@@ -1224,7 +1224,7 @@ static BOOL WINAPI CRYPT_RegDeleteCert(HCERTSTORE hCertStore,
dwFlags); dwFlags);
} }
else else
HeapFree(GetProcessHeap(), 0, toDelete); CryptMemFree(toDelete);
} }
else else
ret = FALSE; ret = FALSE;
...@@ -1297,8 +1297,7 @@ static DWORD CRYPT_RecurseDeleteKey(HKEY hKey, LPCWSTR lpszSubKey) ...@@ -1297,8 +1297,7 @@ static DWORD CRYPT_RecurseDeleteKey(HKEY hKey, LPCWSTR lpszSubKey)
if (dwMaxSubkeyLen > sizeof(szNameBuf)/sizeof(WCHAR)) if (dwMaxSubkeyLen > sizeof(szNameBuf)/sizeof(WCHAR))
{ {
/* Name too big: alloc a buffer for it */ /* Name too big: alloc a buffer for it */
lpszName = HeapAlloc(GetProcessHeap(), 0, lpszName = CryptMemAlloc(dwMaxSubkeyLen*sizeof(WCHAR));
dwMaxSubkeyLen*sizeof(WCHAR));
} }
if (!lpszName) if (!lpszName)
...@@ -1318,7 +1317,7 @@ static DWORD CRYPT_RecurseDeleteKey(HKEY hKey, LPCWSTR lpszSubKey) ...@@ -1318,7 +1317,7 @@ static DWORD CRYPT_RecurseDeleteKey(HKEY hKey, LPCWSTR lpszSubKey)
if (lpszName != szNameBuf) if (lpszName != szNameBuf)
{ {
/* Free buffer if allocated */ /* Free buffer if allocated */
HeapFree(GetProcessHeap(), 0, lpszName); CryptMemFree(lpszName);
} }
} }
} }
...@@ -1363,10 +1362,10 @@ static WINECRYPT_CERTSTORE *CRYPT_RegOpenStore(HCRYPTPROV hCryptProv, ...@@ -1363,10 +1362,10 @@ static WINECRYPT_CERTSTORE *CRYPT_RegOpenStore(HCRYPTPROV hCryptProv,
memStore = CRYPT_MemOpenStore(hCryptProv, dwFlags, NULL); memStore = CRYPT_MemOpenStore(hCryptProv, dwFlags, NULL);
if (memStore) if (memStore)
{ {
store = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, store = CryptMemAlloc(sizeof(WINE_REGSTORE));
sizeof(WINE_REGSTORE));
if (store) if (store)
{ {
memset(store, 0, sizeof(WINE_REGSTORE));
CRYPT_InitStore(&store->hdr, hCryptProv, dwFlags, CRYPT_InitStore(&store->hdr, hCryptProv, dwFlags,
StoreTypeReg); StoreTypeReg);
store->hdr.closeStore = CRYPT_RegCloseStore; store->hdr.closeStore = CRYPT_RegCloseStore;
...@@ -1463,8 +1462,8 @@ static PWINECRYPT_CERTSTORE CRYPT_SysRegOpenStoreW(HCRYPTPROV hCryptProv, ...@@ -1463,8 +1462,8 @@ static PWINECRYPT_CERTSTORE CRYPT_SysRegOpenStoreW(HCRYPTPROV hCryptProv,
return NULL; return NULL;
} }
storePath = HeapAlloc(GetProcessHeap(), 0, (lstrlenW(base) + storePath = CryptMemAlloc((lstrlenW(base) + lstrlenW(storeName) + 2) *
lstrlenW(storeName) + 2) * sizeof(WCHAR)); sizeof(WCHAR));
if (storePath) if (storePath)
{ {
LONG rc; LONG rc;
...@@ -1495,7 +1494,7 @@ static PWINECRYPT_CERTSTORE CRYPT_SysRegOpenStoreW(HCRYPTPROV hCryptProv, ...@@ -1495,7 +1494,7 @@ static PWINECRYPT_CERTSTORE CRYPT_SysRegOpenStoreW(HCRYPTPROV hCryptProv,
} }
else else
SetLastError(rc); SetLastError(rc);
HeapFree(GetProcessHeap(), 0, storePath); CryptMemFree(storePath);
} }
return store; return store;
} }
...@@ -1517,13 +1516,13 @@ static PWINECRYPT_CERTSTORE CRYPT_SysRegOpenStoreA(HCRYPTPROV hCryptProv, ...@@ -1517,13 +1516,13 @@ static PWINECRYPT_CERTSTORE CRYPT_SysRegOpenStoreA(HCRYPTPROV hCryptProv,
len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pvPara, -1, NULL, 0); len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pvPara, -1, NULL, 0);
if (len) if (len)
{ {
LPWSTR storeName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); LPWSTR storeName = CryptMemAlloc(len * sizeof(WCHAR));
if (storeName) if (storeName)
{ {
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pvPara, -1, storeName, len); MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pvPara, -1, storeName, len);
ret = CRYPT_SysRegOpenStoreW(hCryptProv, dwFlags, storeName); ret = CRYPT_SysRegOpenStoreW(hCryptProv, dwFlags, storeName);
HeapFree(GetProcessHeap(), 0, storeName); CryptMemFree(storeName);
} }
} }
return ret; return ret;
...@@ -1600,13 +1599,13 @@ static PWINECRYPT_CERTSTORE CRYPT_SysOpenStoreA(HCRYPTPROV hCryptProv, ...@@ -1600,13 +1599,13 @@ static PWINECRYPT_CERTSTORE CRYPT_SysOpenStoreA(HCRYPTPROV hCryptProv,
len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pvPara, -1, NULL, 0); len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pvPara, -1, NULL, 0);
if (len) if (len)
{ {
LPWSTR storeName = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); LPWSTR storeName = CryptMemAlloc(len * sizeof(WCHAR));
if (storeName) if (storeName)
{ {
MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pvPara, -1, storeName, len); MultiByteToWideChar(CP_ACP, 0, (LPCSTR)pvPara, -1, storeName, len);
ret = CRYPT_SysOpenStoreW(hCryptProv, dwFlags, storeName); ret = CRYPT_SysOpenStoreW(hCryptProv, dwFlags, storeName);
HeapFree(GetProcessHeap(), 0, storeName); CryptMemFree(storeName);
} }
} }
return ret; return ret;
...@@ -1686,13 +1685,13 @@ HCERTSTORE WINAPI CertOpenSystemStoreA(HCRYPTPROV hProv, ...@@ -1686,13 +1685,13 @@ HCERTSTORE WINAPI CertOpenSystemStoreA(HCRYPTPROV hProv,
{ {
int len = MultiByteToWideChar(CP_ACP, 0, szSubSystemProtocol, -1, NULL, int len = MultiByteToWideChar(CP_ACP, 0, szSubSystemProtocol, -1, NULL,
0); 0);
LPWSTR param = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR)); LPWSTR param = CryptMemAlloc(len * sizeof(WCHAR));
if (param) if (param)
{ {
MultiByteToWideChar(CP_ACP, 0, szSubSystemProtocol, -1, param, len); MultiByteToWideChar(CP_ACP, 0, szSubSystemProtocol, -1, param, len);
ret = CertOpenSystemStoreW(hProv, param); ret = CertOpenSystemStoreW(hProv, param);
HeapFree(GetProcessHeap(), 0, param); CryptMemFree(param);
} }
} }
else else
...@@ -1757,14 +1756,14 @@ PCCRL_CONTEXT WINAPI CertCreateCRLContext( DWORD dwCertEncodingType, ...@@ -1757,14 +1756,14 @@ PCCRL_CONTEXT WINAPI CertCreateCRLContext( DWORD dwCertEncodingType,
TRACE("%08lx %p %08lx\n", dwCertEncodingType, pbCrlEncoded, cbCrlEncoded); TRACE("%08lx %p %08lx\n", dwCertEncodingType, pbCrlEncoded, cbCrlEncoded);
/* FIXME: semi-stub, need to use CryptDecodeObjectEx to decode the CRL. */ /* FIXME: semi-stub, need to use CryptDecodeObjectEx to decode the CRL. */
pcrl = HeapAlloc( GetProcessHeap(), 0, sizeof (CRL_CONTEXT) ); pcrl = CryptMemAlloc( sizeof (CRL_CONTEXT) );
if( !pcrl ) if( !pcrl )
return NULL; return NULL;
data = HeapAlloc( GetProcessHeap(), 0, cbCrlEncoded ); data = CryptMemAlloc( cbCrlEncoded );
if( !data ) if( !data )
{ {
HeapFree( GetProcessHeap(), 0, pcrl ); CryptMemFree( pcrl );
return NULL; return NULL;
} }
...@@ -1819,13 +1818,13 @@ static PWINE_CERT_CONTEXT CRYPT_CreateCertificateContext( ...@@ -1819,13 +1818,13 @@ static PWINE_CERT_CONTEXT CRYPT_CreateCertificateContext(
{ {
BYTE *data = NULL; BYTE *data = NULL;
cert = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_CERT_CONTEXT)); cert = CryptMemAlloc(sizeof(WINE_CERT_CONTEXT));
if (!cert) if (!cert)
goto end; goto end;
data = HeapAlloc(GetProcessHeap(), 0, cbCertEncoded); data = CryptMemAlloc(cbCertEncoded);
if (!data) if (!data)
{ {
HeapFree(GetProcessHeap(), 0, cert); CryptMemFree(cert);
cert = NULL; cert = NULL;
goto end; goto end;
} }
...@@ -1848,17 +1847,17 @@ static void CRYPT_FreeCert(PWINE_CERT_CONTEXT context) ...@@ -1848,17 +1847,17 @@ static void CRYPT_FreeCert(PWINE_CERT_CONTEXT context)
{ {
PWINE_CERT_PROPERTY prop, next; PWINE_CERT_PROPERTY prop, next;
HeapFree(GetProcessHeap(), 0, context->cert.pbCertEncoded); CryptMemFree(context->cert.pbCertEncoded);
LocalFree(context->cert.pCertInfo); LocalFree(context->cert.pCertInfo);
DeleteCriticalSection(&context->cs); DeleteCriticalSection(&context->cs);
LIST_FOR_EACH_ENTRY_SAFE(prop, next, &context->extendedProperties, LIST_FOR_EACH_ENTRY_SAFE(prop, next, &context->extendedProperties,
WINE_CERT_PROPERTY, entry) WINE_CERT_PROPERTY, entry)
{ {
list_remove(&prop->entry); list_remove(&prop->entry);
HeapFree(GetProcessHeap(), 0, prop->pbData); CryptMemFree(prop->pbData);
HeapFree(GetProcessHeap(), 0, prop); CryptMemFree(prop);
} }
HeapFree(GetProcessHeap(), 0, context); CryptMemFree(context);
} }
PCCERT_CONTEXT WINAPI CertCreateCertificateContext(DWORD dwCertEncodingType, PCCERT_CONTEXT WINAPI CertCreateCertificateContext(DWORD dwCertEncodingType,
...@@ -2056,7 +2055,7 @@ static BOOL CRYPT_SaveCertificateContextProperty(PWINE_CERT_CONTEXT context, ...@@ -2056,7 +2055,7 @@ static BOOL CRYPT_SaveCertificateContextProperty(PWINE_CERT_CONTEXT context,
if (cbData) if (cbData)
{ {
data = HeapAlloc(GetProcessHeap(), 0, cbData); data = CryptMemAlloc(cbData);
if (data) if (data)
memcpy(data, pbData, cbData); memcpy(data, pbData, cbData);
} }
...@@ -2075,14 +2074,14 @@ static BOOL CRYPT_SaveCertificateContextProperty(PWINE_CERT_CONTEXT context, ...@@ -2075,14 +2074,14 @@ static BOOL CRYPT_SaveCertificateContextProperty(PWINE_CERT_CONTEXT context,
} }
if (prop && prop->entry.next != &context->extendedProperties) if (prop && prop->entry.next != &context->extendedProperties)
{ {
HeapFree(GetProcessHeap(), 0, prop->pbData); CryptMemFree(prop->pbData);
prop->hdr.cb = cbData; prop->hdr.cb = cbData;
prop->pbData = cbData ? data : NULL; prop->pbData = cbData ? data : NULL;
ret = TRUE; ret = TRUE;
} }
else else
{ {
prop = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_CERT_PROPERTY)); prop = CryptMemAlloc(sizeof(WINE_CERT_PROPERTY));
if (prop) if (prop)
{ {
prop->hdr.propID = dwPropId; prop->hdr.propID = dwPropId;
...@@ -2094,7 +2093,7 @@ static BOOL CRYPT_SaveCertificateContextProperty(PWINE_CERT_CONTEXT context, ...@@ -2094,7 +2093,7 @@ static BOOL CRYPT_SaveCertificateContextProperty(PWINE_CERT_CONTEXT context,
ret = TRUE; ret = TRUE;
} }
else else
HeapFree(GetProcessHeap(), 0, data); CryptMemFree(data);
} }
LeaveCriticalSection(&context->cs); LeaveCriticalSection(&context->cs);
} }
...@@ -2119,8 +2118,8 @@ static BOOL WINAPI CRYPT_SetCertificateContextProperty( ...@@ -2119,8 +2118,8 @@ static BOOL WINAPI CRYPT_SetCertificateContextProperty(
if (prop->hdr.propID == dwPropId) if (prop->hdr.propID == dwPropId)
{ {
list_remove(&prop->entry); list_remove(&prop->entry);
HeapFree(GetProcessHeap(), 0, prop->pbData); CryptMemFree(prop->pbData);
HeapFree(GetProcessHeap(), 0, prop); CryptMemFree(prop);
} }
} }
LeaveCriticalSection(&context->cs); LeaveCriticalSection(&context->cs);
...@@ -2205,7 +2204,7 @@ PCCERT_CONTEXT WINAPI CertDuplicateCertificateContext( ...@@ -2205,7 +2204,7 @@ PCCERT_CONTEXT WINAPI CertDuplicateCertificateContext(
TRACE("(%p)\n", pCertContext); TRACE("(%p)\n", pCertContext);
if (ref) if (ref)
{ {
ret = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_CERT_CONTEXT_REF)); ret = CryptMemAlloc(sizeof(WINE_CERT_CONTEXT_REF));
if (ret) if (ret)
{ {
memcpy(ret, ref, sizeof(*ret)); memcpy(ret, ref, sizeof(*ret));
...@@ -2904,7 +2903,7 @@ BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext) ...@@ -2904,7 +2903,7 @@ BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
if (store && store->dwMagic == WINE_CRYPTCERTSTORE_MAGIC && if (store && store->dwMagic == WINE_CRYPTCERTSTORE_MAGIC &&
store->freeCert) store->freeCert)
store->freeCert(ref); store->freeCert(ref);
HeapFree(GetProcessHeap(), 0, ref); CryptMemFree(ref);
} }
return TRUE; return TRUE;
} }
...@@ -2948,7 +2947,7 @@ BOOL WINAPI CertAddStoreToCollection(HCERTSTORE hCollectionStore, ...@@ -2948,7 +2947,7 @@ BOOL WINAPI CertAddStoreToCollection(HCERTSTORE hCollectionStore,
return FALSE; return FALSE;
} }
entry = HeapAlloc(GetProcessHeap(), 0, sizeof(WINE_STORE_LIST_ENTRY)); entry = CryptMemAlloc(sizeof(WINE_STORE_LIST_ENTRY));
if (entry) if (entry)
{ {
InterlockedIncrement(&sibling->ref); InterlockedIncrement(&sibling->ref);
...@@ -3018,7 +3017,7 @@ void WINAPI CertRemoveStoreFromCollection(HCERTSTORE hCollectionStore, ...@@ -3018,7 +3017,7 @@ void WINAPI CertRemoveStoreFromCollection(HCERTSTORE hCollectionStore,
{ {
list_remove(&store->entry); list_remove(&store->entry);
CertCloseStore(store->store, 0); CertCloseStore(store->store, 0);
HeapFree(GetProcessHeap(), 0, store); CryptMemFree(store);
break; break;
} }
} }
......
...@@ -211,7 +211,7 @@ static char *CRYPT_GetKeyName(DWORD dwEncodingType, LPCSTR pszFuncName, ...@@ -211,7 +211,7 @@ static char *CRYPT_GetKeyName(DWORD dwEncodingType, LPCSTR pszFuncName,
* format specifier that are removed by sprintf. * format specifier that are removed by sprintf.
*/ */
len = sizeof(szEncodingTypeFmt) + lstrlenA(pszFuncName) + lstrlenA(oid); len = sizeof(szEncodingTypeFmt) + lstrlenA(pszFuncName) + lstrlenA(oid);
szKey = HeapAlloc(GetProcessHeap(), 0, len); szKey = CryptMemAlloc(len);
if (szKey) if (szKey)
sprintf(szKey, szEncodingTypeFmt, dwEncodingType, pszFuncName, oid); sprintf(szKey, szEncodingTypeFmt, dwEncodingType, pszFuncName, oid);
return szKey; return szKey;
...@@ -255,7 +255,7 @@ BOOL WINAPI CryptRegisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName, ...@@ -255,7 +255,7 @@ BOOL WINAPI CryptRegisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName,
return FALSE; return FALSE;
r = RegCreateKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey); r = RegCreateKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
HeapFree(GetProcessHeap(), 0, szKey); CryptMemFree(szKey);
if(r != ERROR_SUCCESS) if(r != ERROR_SUCCESS)
return FALSE; return FALSE;
...@@ -289,7 +289,7 @@ BOOL WINAPI CryptUnregisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName, ...@@ -289,7 +289,7 @@ BOOL WINAPI CryptUnregisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName,
szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID); szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
rc = RegDeleteKeyA(HKEY_LOCAL_MACHINE, szKey); rc = RegDeleteKeyA(HKEY_LOCAL_MACHINE, szKey);
HeapFree(GetProcessHeap(), 0, szKey); CryptMemFree(szKey);
if (rc) if (rc)
SetLastError(rc); SetLastError(rc);
return rc ? FALSE : TRUE; return rc ? FALSE : TRUE;
...@@ -318,7 +318,7 @@ BOOL WINAPI CryptGetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName, ...@@ -318,7 +318,7 @@ BOOL WINAPI CryptGetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName,
szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID); szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey); rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
HeapFree(GetProcessHeap(), 0, szKey); CryptMemFree(szKey);
if (rc) if (rc)
SetLastError(rc); SetLastError(rc);
else else
...@@ -355,7 +355,7 @@ BOOL WINAPI CryptSetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName, ...@@ -355,7 +355,7 @@ BOOL WINAPI CryptSetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName,
szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID); szKey = CRYPT_GetKeyName(dwEncodingType, pszFuncName, pszOID);
rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey); rc = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
HeapFree(GetProcessHeap(), 0, szKey); CryptMemFree(szKey);
if (rc) if (rc)
SetLastError(rc); SetLastError(rc);
else else
...@@ -390,14 +390,14 @@ static void *CRYPT_GetFunc(DWORD dwCertEncodingType, LPCSTR lpszStructType, ...@@ -390,14 +390,14 @@ static void *CRYPT_GetFunc(DWORD dwCertEncodingType, LPCSTR lpszStructType,
*lib = NULL; *lib = NULL;
r = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey); r = RegOpenKeyA(HKEY_LOCAL_MACHINE, szKey, &hKey);
HeapFree(GetProcessHeap(), 0, szKey); CryptMemFree(szKey);
if(r != ERROR_SUCCESS) if(r != ERROR_SUCCESS)
return NULL; return NULL;
RegQueryValueExA(hKey, "FuncName", NULL, &type, NULL, &size); RegQueryValueExA(hKey, "FuncName", NULL, &type, NULL, &size);
if (GetLastError() == ERROR_MORE_DATA && type == REG_SZ) if (GetLastError() == ERROR_MORE_DATA && type == REG_SZ)
{ {
funcName = HeapAlloc(GetProcessHeap(), 0, size); funcName = CryptMemAlloc(size);
RegQueryValueExA(hKey, "FuncName", NULL, &type, (LPBYTE)funcName, RegQueryValueExA(hKey, "FuncName", NULL, &type, (LPBYTE)funcName,
&size); &size);
} }
...@@ -406,7 +406,7 @@ static void *CRYPT_GetFunc(DWORD dwCertEncodingType, LPCSTR lpszStructType, ...@@ -406,7 +406,7 @@ static void *CRYPT_GetFunc(DWORD dwCertEncodingType, LPCSTR lpszStructType,
RegQueryValueExW(hKey, szDllName, NULL, &type, NULL, &size); RegQueryValueExW(hKey, szDllName, NULL, &type, NULL, &size);
if (GetLastError() == ERROR_MORE_DATA && type == REG_SZ) if (GetLastError() == ERROR_MORE_DATA && type == REG_SZ)
{ {
LPWSTR dllName = HeapAlloc(GetProcessHeap(), 0, size); LPWSTR dllName = CryptMemAlloc(size);
RegQueryValueExW(hKey, szDllName, NULL, &type, (LPBYTE)dllName, RegQueryValueExW(hKey, szDllName, NULL, &type, (LPBYTE)dllName,
&size); &size);
...@@ -423,10 +423,10 @@ static void *CRYPT_GetFunc(DWORD dwCertEncodingType, LPCSTR lpszStructType, ...@@ -423,10 +423,10 @@ static void *CRYPT_GetFunc(DWORD dwCertEncodingType, LPCSTR lpszStructType,
*lib = NULL; *lib = NULL;
} }
} }
HeapFree(GetProcessHeap(), 0, dllName); CryptMemFree(dllName);
} }
if (funcName != szFuncName) if (funcName != szFuncName)
HeapFree(GetProcessHeap(), 0, (char *)funcName); CryptMemFree((char *)funcName);
TRACE("returning %p\n", ret); TRACE("returning %p\n", ret);
return ret; return ret;
} }
...@@ -1330,10 +1330,11 @@ static BOOL WINAPI CRYPT_AsnEncodeRdn(DWORD dwCertEncodingType, CERT_RDN *rdn, ...@@ -1330,10 +1330,11 @@ static BOOL WINAPI CRYPT_AsnEncodeRdn(DWORD dwCertEncodingType, CERT_RDN *rdn,
ret = TRUE; ret = TRUE;
if (rdn->cRDNAttr) if (rdn->cRDNAttr)
{ {
blobs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, blobs = CryptMemAlloc(rdn->cRDNAttr * sizeof(CRYPT_DER_BLOB));
rdn->cRDNAttr * sizeof(CRYPT_DER_BLOB));
if (!blobs) if (!blobs)
ret = FALSE; ret = FALSE;
else
memset(blobs, 0, rdn->cRDNAttr * sizeof(CRYPT_DER_BLOB));
} }
for (i = 0; ret && i < rdn->cRDNAttr; i++) for (i = 0; ret && i < rdn->cRDNAttr; i++)
{ {
...@@ -1357,8 +1358,7 @@ static BOOL WINAPI CRYPT_AsnEncodeRdn(DWORD dwCertEncodingType, CERT_RDN *rdn, ...@@ -1357,8 +1358,7 @@ static BOOL WINAPI CRYPT_AsnEncodeRdn(DWORD dwCertEncodingType, CERT_RDN *rdn,
{ {
for (i = 0; ret && i < rdn->cRDNAttr; i++) for (i = 0; ret && i < rdn->cRDNAttr; i++)
{ {
blobs[i].pbData = HeapAlloc(GetProcessHeap(), 0, blobs[i].pbData = CryptMemAlloc(blobs[i].cbData);
blobs[i].cbData);
if (!blobs[i].pbData) if (!blobs[i].pbData)
ret = FALSE; ret = FALSE;
else else
...@@ -1387,7 +1387,7 @@ static BOOL WINAPI CRYPT_AsnEncodeRdn(DWORD dwCertEncodingType, CERT_RDN *rdn, ...@@ -1387,7 +1387,7 @@ static BOOL WINAPI CRYPT_AsnEncodeRdn(DWORD dwCertEncodingType, CERT_RDN *rdn,
if (blobs) if (blobs)
{ {
for (i = 0; i < rdn->cRDNAttr; i++) for (i = 0; i < rdn->cRDNAttr; i++)
HeapFree(GetProcessHeap(), 0, blobs[i].pbData); CryptMemFree(blobs[i].pbData);
} }
} }
__EXCEPT(page_fault) __EXCEPT(page_fault)
...@@ -1396,7 +1396,7 @@ static BOOL WINAPI CRYPT_AsnEncodeRdn(DWORD dwCertEncodingType, CERT_RDN *rdn, ...@@ -1396,7 +1396,7 @@ static BOOL WINAPI CRYPT_AsnEncodeRdn(DWORD dwCertEncodingType, CERT_RDN *rdn,
return FALSE; return FALSE;
} }
__ENDTRY __ENDTRY
HeapFree(GetProcessHeap(), 0, blobs); CryptMemFree(blobs);
return ret; return ret;
} }
...@@ -1866,7 +1866,7 @@ static BOOL WINAPI CRYPT_AsnEncodeBitsSwapBytes(DWORD dwCertEncodingType, ...@@ -1866,7 +1866,7 @@ static BOOL WINAPI CRYPT_AsnEncodeBitsSwapBytes(DWORD dwCertEncodingType,
ret = TRUE; ret = TRUE;
if (newBlob.cbData) if (newBlob.cbData)
{ {
newBlob.pbData = HeapAlloc(GetProcessHeap(), 0, newBlob.cbData); newBlob.pbData = CryptMemAlloc(newBlob.cbData);
if (newBlob.pbData) if (newBlob.pbData)
{ {
DWORD i; DWORD i;
...@@ -1880,7 +1880,7 @@ static BOOL WINAPI CRYPT_AsnEncodeBitsSwapBytes(DWORD dwCertEncodingType, ...@@ -1880,7 +1880,7 @@ static BOOL WINAPI CRYPT_AsnEncodeBitsSwapBytes(DWORD dwCertEncodingType,
if (ret) if (ret)
ret = CRYPT_AsnEncodeBits(dwCertEncodingType, lpszStructType, ret = CRYPT_AsnEncodeBits(dwCertEncodingType, lpszStructType,
&newBlob, dwFlags, pEncodePara, pbEncoded, pcbEncoded); &newBlob, dwFlags, pEncodePara, pbEncoded, pcbEncoded);
HeapFree(GetProcessHeap(), 0, newBlob.pbData); CryptMemFree(newBlob.pbData);
} }
__EXCEPT(page_fault) __EXCEPT(page_fault)
{ {
...@@ -5547,7 +5547,7 @@ static BOOL WINAPI CRYPT_ExportRsaPublicKeyInfoEx(HCRYPTPROV hCryptProv, ...@@ -5547,7 +5547,7 @@ static BOOL WINAPI CRYPT_ExportRsaPublicKeyInfoEx(HCRYPTPROV hCryptProv,
ret = CryptExportKey(key, 0, PUBLICKEYBLOB, 0, NULL, &keySize); ret = CryptExportKey(key, 0, PUBLICKEYBLOB, 0, NULL, &keySize);
if (ret) if (ret)
{ {
LPBYTE pubKey = HeapAlloc(GetProcessHeap(), 0, keySize); LPBYTE pubKey = CryptMemAlloc(keySize);
if (pubKey) if (pubKey)
{ {
...@@ -5591,7 +5591,7 @@ static BOOL WINAPI CRYPT_ExportRsaPublicKeyInfoEx(HCRYPTPROV hCryptProv, ...@@ -5591,7 +5591,7 @@ static BOOL WINAPI CRYPT_ExportRsaPublicKeyInfoEx(HCRYPTPROV hCryptProv,
} }
} }
} }
HeapFree(GetProcessHeap(), 0, pubKey); CryptMemFree(pubKey);
} }
else else
ret = FALSE; ret = FALSE;
...@@ -5656,7 +5656,7 @@ static BOOL WINAPI CRYPT_ImportRsaPublicKeyInfoEx(HCRYPTPROV hCryptProv, ...@@ -5656,7 +5656,7 @@ static BOOL WINAPI CRYPT_ImportRsaPublicKeyInfoEx(HCRYPTPROV hCryptProv,
pInfo->PublicKey.pbData, pInfo->PublicKey.cbData, 0, NULL, &pubKeySize); pInfo->PublicKey.pbData, pInfo->PublicKey.cbData, 0, NULL, &pubKeySize);
if (ret) if (ret)
{ {
LPBYTE pubKey = HeapAlloc(GetProcessHeap(), 0, pubKeySize); LPBYTE pubKey = CryptMemAlloc(pubKeySize);
if (pubKey) if (pubKey)
{ {
...@@ -5666,7 +5666,7 @@ static BOOL WINAPI CRYPT_ImportRsaPublicKeyInfoEx(HCRYPTPROV hCryptProv, ...@@ -5666,7 +5666,7 @@ static BOOL WINAPI CRYPT_ImportRsaPublicKeyInfoEx(HCRYPTPROV hCryptProv,
if (ret) if (ret)
ret = CryptImportKey(hCryptProv, pubKey, pubKeySize, 0, 0, ret = CryptImportKey(hCryptProv, pubKey, pubKeySize, 0, 0,
phKey); phKey);
HeapFree(GetProcessHeap(), 0, pubKey); CryptMemFree(pubKey);
} }
else else
ret = FALSE; ret = FALSE;
......
...@@ -196,7 +196,7 @@ BOOL unserialize_string(BYTE * ptr, DWORD *index, DWORD size, ...@@ -196,7 +196,7 @@ BOOL unserialize_string(BYTE * ptr, DWORD *index, DWORD size,
return FALSE; return FALSE;
} }
if (!(*data = HeapAlloc( GetProcessHeap(), 0, len*width))) if (!(*data = CryptMemAlloc( len*width)))
{ {
return FALSE; return FALSE;
} }
...@@ -538,19 +538,19 @@ void free_protect_data(struct protect_data_t * pInfo) ...@@ -538,19 +538,19 @@ void free_protect_data(struct protect_data_t * pInfo)
if (!pInfo) return; if (!pInfo) return;
if (pInfo->info0.pbData) if (pInfo->info0.pbData)
HeapFree( GetProcessHeap(), 0, pInfo->info0.pbData); CryptMemFree(pInfo->info0.pbData);
if (pInfo->info1.pbData) if (pInfo->info1.pbData)
HeapFree( GetProcessHeap(), 0, pInfo->info1.pbData); CryptMemFree(pInfo->info1.pbData);
if (pInfo->szDataDescr) if (pInfo->szDataDescr)
HeapFree( GetProcessHeap(), 0, pInfo->szDataDescr); CryptMemFree(pInfo->szDataDescr);
if (pInfo->data0.pbData) if (pInfo->data0.pbData)
HeapFree( GetProcessHeap(), 0, pInfo->data0.pbData); CryptMemFree(pInfo->data0.pbData);
if (pInfo->salt.pbData) if (pInfo->salt.pbData)
HeapFree( GetProcessHeap(), 0, pInfo->salt.pbData); CryptMemFree(pInfo->salt.pbData);
if (pInfo->cipher.pbData) if (pInfo->cipher.pbData)
HeapFree( GetProcessHeap(), 0, pInfo->cipher.pbData); CryptMemFree(pInfo->cipher.pbData);
if (pInfo->fingerprint.pbData) if (pInfo->fingerprint.pbData)
HeapFree( GetProcessHeap(), 0, pInfo->fingerprint.pbData); CryptMemFree(pInfo->fingerprint.pbData);
} }
/* copies a string into a data blob */ /* copies a string into a data blob */
...@@ -560,7 +560,7 @@ BYTE * convert_str_to_blob(char* str, DATA_BLOB* blob) ...@@ -560,7 +560,7 @@ BYTE * convert_str_to_blob(char* str, DATA_BLOB* blob)
if (!str || !blob) return NULL; if (!str || !blob) return NULL;
blob->cbData=strlen(str)+1; blob->cbData=strlen(str)+1;
if (!(blob->pbData=HeapAlloc(GetProcessHeap(),0,blob->cbData))) if (!(blob->pbData=CryptMemAlloc(blob->cbData)))
{ {
blob->cbData=0; blob->cbData=0;
} }
...@@ -598,7 +598,7 @@ BOOL fill_protect_data(struct protect_data_t * pInfo, LPCWSTR szDataDescr, ...@@ -598,7 +598,7 @@ BOOL fill_protect_data(struct protect_data_t * pInfo, LPCWSTR szDataDescr,
pInfo->null0=0x0000; pInfo->null0=0x0000;
if ((pInfo->szDataDescr=HeapAlloc( GetProcessHeap(), 0, (dwStrLen+1)*sizeof(WCHAR)))) if ((pInfo->szDataDescr=CryptMemAlloc((dwStrLen+1)*sizeof(WCHAR))))
{ {
memcpy(pInfo->szDataDescr,szDataDescr,(dwStrLen+1)*sizeof(WCHAR)); memcpy(pInfo->szDataDescr,szDataDescr,(dwStrLen+1)*sizeof(WCHAR));
} }
...@@ -614,7 +614,7 @@ BOOL fill_protect_data(struct protect_data_t * pInfo, LPCWSTR szDataDescr, ...@@ -614,7 +614,7 @@ BOOL fill_protect_data(struct protect_data_t * pInfo, LPCWSTR szDataDescr,
/* allocate memory to hold a salt */ /* allocate memory to hold a salt */
pInfo->salt.cbData=CRYPT32_PROTECTDATA_SALT_LEN; pInfo->salt.cbData=CRYPT32_PROTECTDATA_SALT_LEN;
if ((pInfo->salt.pbData=HeapAlloc( GetProcessHeap(),0,pInfo->salt.cbData))) if ((pInfo->salt.pbData=CryptMemAlloc(pInfo->salt.cbData)))
{ {
/* generate random salt */ /* generate random salt */
if (!CryptGenRandom(hProv, pInfo->salt.cbData, pInfo->salt.pbData)) if (!CryptGenRandom(hProv, pInfo->salt.cbData, pInfo->salt.pbData))
...@@ -667,7 +667,7 @@ BOOL convert_hash_to_blob(HCRYPTHASH hHash, DATA_BLOB * blob) ...@@ -667,7 +667,7 @@ BOOL convert_hash_to_blob(HCRYPTHASH hHash, DATA_BLOB * blob)
return FALSE; return FALSE;
} }
if (!(blob->pbData=HeapAlloc( GetProcessHeap(), 0, blob->cbData))) if (!(blob->pbData=CryptMemAlloc(blob->cbData)))
{ {
ERR("failed to allocate blob memory\n"); ERR("failed to allocate blob memory\n");
return FALSE; return FALSE;
...@@ -677,7 +677,7 @@ BOOL convert_hash_to_blob(HCRYPTHASH hHash, DATA_BLOB * blob) ...@@ -677,7 +677,7 @@ BOOL convert_hash_to_blob(HCRYPTHASH hHash, DATA_BLOB * blob)
if (!CryptGetHashParam(hHash, HP_HASHVAL, blob->pbData, &dwSize, 0)) if (!CryptGetHashParam(hHash, HP_HASHVAL, blob->pbData, &dwSize, 0))
{ {
ERR("failed to get hash value\n"); ERR("failed to get hash value\n");
HeapFree( GetProcessHeap(), 0, blob->pbData); CryptMemFree(blob->pbData);
blob->pbData=NULL; blob->pbData=NULL;
blob->cbData=0; blob->cbData=0;
return FALSE; return FALSE;
...@@ -705,7 +705,7 @@ BOOL hash_matches_blob(HCRYPTHASH hHash, DATA_BLOB * two) ...@@ -705,7 +705,7 @@ BOOL hash_matches_blob(HCRYPTHASH hHash, DATA_BLOB * two)
rc = TRUE; rc = TRUE;
} }
HeapFree( GetProcessHeap(), 0, one.pbData ); CryptMemFree(one.pbData);
return rc; return rc;
} }
...@@ -733,7 +733,7 @@ BOOL load_encryption_key(HCRYPTPROV hProv, DATA_BLOB * salt, ...@@ -733,7 +733,7 @@ BOOL load_encryption_key(HCRYPTPROV hProv, DATA_BLOB * salt,
dwUsernameLen = 0; dwUsernameLen = 0;
if (!GetUserNameA(NULL,&dwUsernameLen) && if (!GetUserNameA(NULL,&dwUsernameLen) &&
GetLastError()==ERROR_MORE_DATA && dwUsernameLen && GetLastError()==ERROR_MORE_DATA && dwUsernameLen &&
(szUsername = HeapAlloc( GetProcessHeap(), 0, dwUsernameLen))) (szUsername = CryptMemAlloc(dwUsernameLen)))
{ {
szUsername[0]='\0'; szUsername[0]='\0';
GetUserNameA( szUsername, &dwUsernameLen ); GetUserNameA( szUsername, &dwUsernameLen );
...@@ -768,7 +768,7 @@ BOOL load_encryption_key(HCRYPTPROV hProv, DATA_BLOB * salt, ...@@ -768,7 +768,7 @@ BOOL load_encryption_key(HCRYPTPROV hProv, DATA_BLOB * salt,
/* clean up */ /* clean up */
CryptDestroyHash(hSaltHash); CryptDestroyHash(hSaltHash);
if (szUsername) HeapFree( GetProcessHeap(), 0, szUsername ); if (szUsername) CryptMemFree(szUsername);
return rc; return rc;
} }
...@@ -902,10 +902,10 @@ BOOL WINAPI CryptProtectData(DATA_BLOB* pDataIn, ...@@ -902,10 +902,10 @@ BOOL WINAPI CryptProtectData(DATA_BLOB* pDataIn,
/* copy plain text into cipher area for CryptEncrypt call */ /* copy plain text into cipher area for CryptEncrypt call */
protect_data.cipher.cbData=dwLength; protect_data.cipher.cbData=dwLength;
if (!(protect_data.cipher.pbData=HeapAlloc( GetProcessHeap(), 0, if (!(protect_data.cipher.pbData=CryptMemAlloc(
protect_data.cipher.cbData))) protect_data.cipher.cbData)))
{ {
ERR("HeapAlloc\n"); ERR("CryptMemAlloc\n");
goto free_hash; goto free_hash;
} }
memcpy(protect_data.cipher.pbData,pDataIn->pbData,pDataIn->cbData); memcpy(protect_data.cipher.pbData,pDataIn->pbData,pDataIn->cbData);
...@@ -1068,7 +1068,7 @@ BOOL WINAPI CryptUnprotectData(DATA_BLOB* pDataIn, ...@@ -1068,7 +1068,7 @@ BOOL WINAPI CryptUnprotectData(DATA_BLOB* pDataIn,
pDataOut->cbData=protect_data.cipher.cbData; pDataOut->cbData=protect_data.cipher.cbData;
if (!(pDataOut->pbData=LocalAlloc( LPTR, pDataOut->cbData))) if (!(pDataOut->pbData=LocalAlloc( LPTR, pDataOut->cbData)))
{ {
ERR("HeapAlloc\n"); ERR("CryptMemAlloc\n");
goto free_hash; goto free_hash;
} }
memcpy(pDataOut->pbData,protect_data.cipher.pbData,protect_data.cipher.cbData); memcpy(pDataOut->pbData,protect_data.cipher.pbData,protect_data.cipher.cbData);
......
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