dssenh: Use CRT allocation functions.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
This commit is contained in:
Nikolay Sivov 2022-09-08 12:42:00 +03:00 committed by Alexandre Julliard
parent 76dc764139
commit d32f9ef316

View file

@ -31,7 +31,6 @@
#include "ntsecapi.h"
#include "wine/debug.h"
#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(dssenh);
@ -88,7 +87,7 @@ static struct container *create_key_container( const char *name, DWORD flags )
{
struct container *ret;
if (!(ret = heap_alloc_zero( sizeof(*ret) ))) return NULL;
if (!(ret = calloc( 1, sizeof(*ret) ))) return NULL;
ret->magic = MAGIC_CONTAINER;
ret->flags = flags;
if (name) strcpy( ret->name, name );
@ -154,14 +153,14 @@ static struct key *create_key( ALG_ID algid, DWORD flags )
return NULL;
}
if (!(ret = heap_alloc_zero( sizeof(*ret) ))) return NULL;
if (!(ret = calloc( 1, sizeof(*ret) ))) return NULL;
ret->magic = MAGIC_KEY;
ret->algid = algid;
ret->flags = flags;
if (BCryptOpenAlgorithmProvider( &ret->alg_handle, alg, MS_PRIMITIVE_PROVIDER, 0 ))
{
heap_free( ret );
free( ret );
return NULL;
}
return ret;
@ -173,7 +172,7 @@ static void destroy_key( struct key *key )
BCryptDestroyKey( key->handle );
BCryptCloseAlgorithmProvider( key->alg_handle, 0 );
key->magic = 0;
heap_free( key );
free( key );
}
static struct key *import_key( DWORD keyspec, BYTE *data, DWORD len )
@ -201,7 +200,7 @@ static struct key *read_key( HKEY hkey, DWORD keyspec, DWORD flags )
if (!(value = map_keyspec_to_keypair_name( keyspec ))) return NULL;
if (RegQueryValueExW( hkey, value, 0, &type, NULL, &len )) return NULL;
if (!(data = heap_alloc( len ))) return NULL;
if (!(data = malloc( len ))) return NULL;
if (!RegQueryValueExW( hkey, value, 0, &type, data, &len ))
{
@ -214,7 +213,7 @@ static struct key *read_key( HKEY hkey, DWORD keyspec, DWORD flags )
}
}
heap_free( data );
free( data );
return ret;
}
@ -224,7 +223,7 @@ static void destroy_container( struct container *container )
destroy_key( container->exch_key );
destroy_key( container->sign_key );
container->magic = 0;
heap_free( container );
free( container );
}
static struct container *read_key_container( const char *name, DWORD flags )
@ -292,7 +291,7 @@ BOOL WINAPI CPAcquireContext( HCRYPTPROV *ret_prov, LPSTR container, DWORD flags
case CRYPT_NEWKEYSET | CRYPT_MACHINE_KEYSET:
if ((ret = read_key_container( name, flags )))
{
heap_free( ret );
free( ret );
SetLastError( NTE_EXISTS );
return FALSE;
}
@ -348,7 +347,7 @@ static BOOL store_key_pair( struct key *key, HKEY hkey, DWORD keyspec, DWORD fla
if (!(value = map_keyspec_to_keypair_name( keyspec ))) return FALSE;
if (BCryptExportKey( key->handle, NULL, LEGACY_DSA_V2_PRIVATE_BLOB, NULL, 0, &len, 0 )) return FALSE;
if (!(data = heap_alloc( len ))) return FALSE;
if (!(data = malloc( len ))) return FALSE;
if (!BCryptExportKey( key->handle, NULL, LEGACY_DSA_V2_PRIVATE_BLOB, data, len, &len, 0 ))
{
@ -361,7 +360,7 @@ static BOOL store_key_pair( struct key *key, HKEY hkey, DWORD keyspec, DWORD fla
}
}
heap_free( data );
free( data );
return ret;
}
@ -392,7 +391,7 @@ static struct key *duplicate_key( const struct key *key )
if (BCryptDuplicateKey( key->handle, &ret->handle, NULL, 0, 0 ))
{
heap_free( ret );
free( ret );
return NULL;
}
return ret;
@ -596,7 +595,7 @@ static BOOL import_key_dss3( struct container *container, ALG_ID algid, const BY
if (!(key = create_key( CALG_DSS_SIGN, flags ))) return FALSE;
size = sizeof(*blob) + (pubkey->bitlenP / 8) * 3;
if (!(blob = heap_alloc_zero( size )))
if (!(blob = calloc( 1, size )))
{
destroy_key( key );
return FALSE;
@ -630,11 +629,11 @@ static BOOL import_key_dss3( struct container *container, ALG_ID algid, const BY
{
WARN( "failed to import key %08lx\n", status );
destroy_key( key );
heap_free( blob );
free( blob );
return FALSE;
}
heap_free( blob );
free( blob );
*ret_key = (HCRYPTKEY)key;
return TRUE;
}
@ -792,19 +791,19 @@ static struct hash *create_hash( ALG_ID algid )
return NULL;
}
if (!(ret = heap_alloc_zero( sizeof(*ret) ))) return NULL;
if (!(ret = calloc( 1, sizeof(*ret) ))) return NULL;
ret->magic = MAGIC_HASH;
ret->len = len;
if (BCryptOpenAlgorithmProvider( &alg_handle, alg, MS_PRIMITIVE_PROVIDER, 0 ))
{
heap_free( ret );
free( ret );
return NULL;
}
if (BCryptCreateHash( alg_handle, &ret->handle, NULL, 0, NULL, 0, 0 ))
{
BCryptCloseAlgorithmProvider( alg_handle, 0 );
heap_free( ret );
free( ret );
return NULL;
}
@ -841,7 +840,7 @@ static void destroy_hash( struct hash *hash )
if (!hash) return;
BCryptDestroyHash( hash->handle );
hash->magic = 0;
heap_free( hash );
free( hash );
}
BOOL WINAPI CPDestroyHash( HCRYPTPROV hprov, HCRYPTHASH hhash )
@ -864,13 +863,13 @@ static struct hash *duplicate_hash( const struct hash *hash )
{
struct hash *ret;
if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
if (!(ret = malloc( sizeof(*ret) ))) return NULL;
ret->magic = hash->magic;
ret->len = hash->len;
if (BCryptDuplicateHash( hash->handle, &ret->handle, NULL, 0, 0 ))
{
heap_free( ret );
free( ret );
return NULL;
}
memcpy( ret->value, hash->value, sizeof(hash->value) );