Commit 1fb28509 authored by Hans Leidekker's avatar Hans Leidekker Committed by Alexandre Julliard

crypt32: Consistently use CryptMemAlloc/Free().

parent dd91e541
...@@ -677,7 +677,7 @@ static BOOL CertContext_SetKeyProvInfoProperty(CONTEXT_PROPERTY_LIST *properties ...@@ -677,7 +677,7 @@ static BOOL CertContext_SetKeyProvInfoProperty(CONTEXT_PROPERTY_LIST *properties
for (i = 0; i < info->cProvParam; i++) for (i = 0; i < info->cProvParam; i++)
size += sizeof(CRYPT_KEY_PROV_PARAM) + info->rgProvParam[i].cbData; size += sizeof(CRYPT_KEY_PROV_PARAM) + info->rgProvParam[i].cbData;
prop = HeapAlloc(GetProcessHeap(), 0, size); prop = CryptMemAlloc(size);
if (!prop) if (!prop)
{ {
SetLastError(ERROR_OUTOFMEMORY); SetLastError(ERROR_OUTOFMEMORY);
...@@ -687,7 +687,7 @@ static BOOL CertContext_SetKeyProvInfoProperty(CONTEXT_PROPERTY_LIST *properties ...@@ -687,7 +687,7 @@ static BOOL CertContext_SetKeyProvInfoProperty(CONTEXT_PROPERTY_LIST *properties
copy_KeyProvInfoProperty(info, prop); copy_KeyProvInfoProperty(info, prop);
ret = ContextPropertyList_SetProperty(properties, CERT_KEY_PROV_INFO_PROP_ID, (const BYTE *)prop, size); ret = ContextPropertyList_SetProperty(properties, CERT_KEY_PROV_INFO_PROP_ID, (const BYTE *)prop, size);
HeapFree(GetProcessHeap(), 0, prop); CryptMemFree(prop);
return ret; return ret;
} }
...@@ -865,7 +865,7 @@ static BOOL CRYPT_AcquirePrivateKeyFromProvInfo(PCCERT_CONTEXT pCert, DWORD dwFl ...@@ -865,7 +865,7 @@ static BOOL CRYPT_AcquirePrivateKeyFromProvInfo(PCCERT_CONTEXT pCert, DWORD dwFl
CERT_KEY_PROV_INFO_PROP_ID, 0, &size); CERT_KEY_PROV_INFO_PROP_ID, 0, &size);
if (ret) if (ret)
{ {
info = HeapAlloc(GetProcessHeap(), 0, size); info = CryptMemAlloc(size);
if (info) if (info)
{ {
ret = CertGetCertificateContextProperty(pCert, ret = CertGetCertificateContextProperty(pCert,
...@@ -901,7 +901,7 @@ static BOOL CRYPT_AcquirePrivateKeyFromProvInfo(PCCERT_CONTEXT pCert, DWORD dwFl ...@@ -901,7 +901,7 @@ static BOOL CRYPT_AcquirePrivateKeyFromProvInfo(PCCERT_CONTEXT pCert, DWORD dwFl
SetLastError(CRYPT_E_NO_KEY_PROPERTY); SetLastError(CRYPT_E_NO_KEY_PROPERTY);
} }
if (allocated) if (allocated)
HeapFree(GetProcessHeap(), 0, info); CryptMemFree(info);
return ret; return ret;
} }
...@@ -953,7 +953,7 @@ BOOL WINAPI CryptAcquireCertificatePrivateKey(PCCERT_CONTEXT pCert, ...@@ -953,7 +953,7 @@ BOOL WINAPI CryptAcquireCertificatePrivateKey(PCCERT_CONTEXT pCert,
if (ret) if (ret)
{ {
info = HeapAlloc(GetProcessHeap(), 0, size); info = CryptMemAlloc(size);
ret = CertGetCertificateContextProperty(pCert, ret = CertGetCertificateContextProperty(pCert,
CERT_KEY_PROV_INFO_PROP_ID, info, &size); CERT_KEY_PROV_INFO_PROP_ID, info, &size);
if (ret) if (ret)
...@@ -1003,7 +1003,7 @@ BOOL WINAPI CryptAcquireCertificatePrivateKey(PCCERT_CONTEXT pCert, ...@@ -1003,7 +1003,7 @@ BOOL WINAPI CryptAcquireCertificatePrivateKey(PCCERT_CONTEXT pCert,
} }
} }
} }
HeapFree(GetProcessHeap(), 0, info); CryptMemFree(info);
if (cert_in_store) if (cert_in_store)
CertFreeCertificateContext(cert_in_store); CertFreeCertificateContext(cert_in_store);
return ret; return ret;
......
...@@ -2007,7 +2007,7 @@ static PCCERT_CONTEXT CRYPT_FindIssuer(const CertificateChainEngine *engine, con ...@@ -2007,7 +2007,7 @@ static PCCERT_CONTEXT CRYPT_FindIssuer(const CertificateChainEngine *engine, con
if(!res) if(!res)
return NULL; return NULL;
urls = HeapAlloc(GetProcessHeap(), 0, size); urls = CryptMemAlloc(size);
if(!urls) if(!urls)
return NULL; return NULL;
...@@ -2045,7 +2045,7 @@ static PCCERT_CONTEXT CRYPT_FindIssuer(const CertificateChainEngine *engine, con ...@@ -2045,7 +2045,7 @@ static PCCERT_CONTEXT CRYPT_FindIssuer(const CertificateChainEngine *engine, con
} }
} }
HeapFree(GetProcessHeap(), 0, urls); CryptMemFree(urls);
return issuer; return issuer;
} }
......
...@@ -1666,12 +1666,12 @@ static BOOL CRYPT_ExportEncryptedKey(CMSG_CONTENT_ENCRYPT_INFO *info, DWORD i, ...@@ -1666,12 +1666,12 @@ static BOOL CRYPT_ExportEncryptedKey(CMSG_CONTENT_ENCRYPT_INFO *info, DWORD i,
static LPVOID WINAPI mem_alloc(size_t size) static LPVOID WINAPI mem_alloc(size_t size)
{ {
return HeapAlloc(GetProcessHeap(), 0, size); return CryptMemAlloc(size);
} }
static VOID WINAPI mem_free(LPVOID pv) static VOID WINAPI mem_free(LPVOID pv)
{ {
HeapFree(GetProcessHeap(), 0, pv); CryptMemFree(pv);
} }
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
*/ */
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h>
#include "ntstatus.h" #include "ntstatus.h"
#define WIN32_NO_STATUS #define WIN32_NO_STATUS
...@@ -28,7 +27,6 @@ ...@@ -28,7 +27,6 @@
#include "crypt32_private.h" #include "crypt32_private.h"
#include "wine/debug.h" #include "wine/debug.h"
#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(crypt); WINE_DEFAULT_DEBUG_CHANNEL(crypt);
...@@ -55,17 +53,17 @@ static HCRYPTPROV import_key( cert_store_data_t data, DWORD flags ) ...@@ -55,17 +53,17 @@ static HCRYPTPROV import_key( cert_store_data_t data, DWORD flags )
} }
} }
params.buf = key = malloc( size ); params.buf = key = CryptMemAlloc( size );
if (CRYPT32_CALL( import_store_key, &params ) || if (CRYPT32_CALL( import_store_key, &params ) ||
!CryptImportKey( prov, key, size, 0, flags & CRYPT_EXPORTABLE, &cryptkey )) !CryptImportKey( prov, key, size, 0, flags & CRYPT_EXPORTABLE, &cryptkey ))
{ {
WARN( "CryptImportKey failed %08lx\n", GetLastError() ); WARN( "CryptImportKey failed %08lx\n", GetLastError() );
CryptReleaseContext( prov, 0 ); CryptReleaseContext( prov, 0 );
free( key ); CryptMemFree( key );
return 0; return 0;
} }
CryptDestroyKey( cryptkey ); CryptDestroyKey( cryptkey );
free( key ); CryptMemFree( key );
return prov; return prov;
} }
...@@ -177,10 +175,10 @@ HCERTSTORE WINAPI PFXImportCertStore( CRYPT_DATA_BLOB *pfx, const WCHAR *passwor ...@@ -177,10 +175,10 @@ HCERTSTORE WINAPI PFXImportCertStore( CRYPT_DATA_BLOB *pfx, const WCHAR *passwor
struct import_store_cert_params import_params = { data, i, NULL, &size }; struct import_store_cert_params import_params = { data, i, NULL, &size };
if (CRYPT32_CALL( import_store_cert, &import_params ) != STATUS_BUFFER_TOO_SMALL) break; if (CRYPT32_CALL( import_store_cert, &import_params ) != STATUS_BUFFER_TOO_SMALL) break;
import_params.buf = cert = malloc( size ); import_params.buf = cert = CryptMemAlloc( size );
if (!CRYPT32_CALL( import_store_cert, &import_params )) if (!CRYPT32_CALL( import_store_cert, &import_params ))
ctx = CertCreateContext( CERT_STORE_CERTIFICATE_CONTEXT, X509_ASN_ENCODING, cert, size, 0, NULL ); ctx = CertCreateContext( CERT_STORE_CERTIFICATE_CONTEXT, X509_ASN_ENCODING, cert, size, 0, NULL );
free( cert ); CryptMemFree( cert );
if (!ctx) if (!ctx)
{ {
WARN( "CertCreateContext failed %08lx\n", GetLastError() ); WARN( "CertCreateContext failed %08lx\n", GetLastError() );
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include "ntstatus.h" #include "ntstatus.h"
#define WIN32_NO_STATUS #define WIN32_NO_STATUS
...@@ -622,19 +621,19 @@ static void read_trusted_roots_from_known_locations(HCERTSTORE store) ...@@ -622,19 +621,19 @@ static void read_trusted_roots_from_known_locations(HCERTSTORE store)
if (from) if (from)
{ {
params.buffer = malloc( params.size ); params.buffer = CryptMemAlloc( params.size );
while (!CRYPT32_CALL( enum_root_certs, &params )) while (!CRYPT32_CALL( enum_root_certs, &params ))
{ {
if (needed > params.size) if (needed > params.size)
{ {
free( params.buffer ); CryptMemFree( params.buffer );
params.buffer = malloc( needed ); params.buffer = CryptMemAlloc( needed );
params.size = needed; params.size = needed;
} }
else CertAddEncodedCertificateToStore( from, X509_ASN_ENCODING, params.buffer, needed, else CertAddEncodedCertificateToStore( from, X509_ASN_ENCODING, params.buffer, needed,
CERT_STORE_ADD_NEW, NULL ); CERT_STORE_ADD_NEW, NULL );
} }
free( params.buffer ); CryptMemFree( params.buffer );
check_and_store_certs(from, store); check_and_store_certs(from, store);
} }
CertCloseStore(from, 0); CertCloseStore(from, 0);
......
...@@ -72,7 +72,7 @@ static DWORD serialize_KeyProvInfoProperty(const CRYPT_KEY_PROV_INFO *info, stru ...@@ -72,7 +72,7 @@ static DWORD serialize_KeyProvInfoProperty(const CRYPT_KEY_PROV_INFO *info, stru
if (!ret) return size; if (!ret) return size;
store = HeapAlloc(GetProcessHeap(), 0, size); store = CryptMemAlloc(size);
if (!store) return 0; if (!store) return 0;
param = (struct store_CRYPT_KEY_PROV_PARAM *)(store + 1); param = (struct store_CRYPT_KEY_PROV_PARAM *)(store + 1);
...@@ -331,7 +331,7 @@ static DWORD read_serialized_KeyProvInfoProperty(const struct store_CRYPT_KEY_PR ...@@ -331,7 +331,7 @@ static DWORD read_serialized_KeyProvInfoProperty(const struct store_CRYPT_KEY_PR
for (i = 0; i < store->cProvParam; i++) for (i = 0; i < store->cProvParam; i++)
size += sizeof(CRYPT_KEY_PROV_PARAM) + param[i].cbData; size += sizeof(CRYPT_KEY_PROV_PARAM) + param[i].cbData;
info = HeapAlloc(GetProcessHeap(), 0, size); info = CryptMemAlloc(size);
if (!info) if (!info)
{ {
SetLastError(ERROR_OUTOFMEMORY); SetLastError(ERROR_OUTOFMEMORY);
......
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