1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

Replace malloc with calloc

- platform layer currently broken (not adapted yet)
- memmory_buffer_alloc too
This commit is contained in:
Manuel Pégourié-Gonnard
2015-05-26 16:04:06 +02:00
parent 065122cfe9
commit 7551cb9ee9
31 changed files with 122 additions and 131 deletions

View File

@ -70,7 +70,7 @@
#include "mbedtls/platform.h"
#else
#include <stdlib.h>
#define mbedtls_malloc malloc
#define mbedtls_calloc calloc
#define mbedtls_free free
#endif
@ -78,7 +78,7 @@
/* shared by all GCM ciphers */
static void *gcm_ctx_alloc( void )
{
return mbedtls_malloc( sizeof( mbedtls_gcm_context ) );
return mbedtls_calloc( 1, sizeof( mbedtls_gcm_context ) );
}
static void gcm_ctx_free( void *ctx )
@ -92,7 +92,7 @@ static void gcm_ctx_free( void *ctx )
/* shared by all CCM ciphers */
static void *ccm_ctx_alloc( void )
{
return mbedtls_malloc( sizeof( mbedtls_ccm_context ) );
return mbedtls_calloc( 1, sizeof( mbedtls_ccm_context ) );
}
static void ccm_ctx_free( void *ctx )
@ -153,7 +153,7 @@ static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
static void * aes_ctx_alloc( void )
{
mbedtls_aes_context *aes = mbedtls_malloc( sizeof( mbedtls_aes_context ) );
mbedtls_aes_context *aes = mbedtls_calloc( 1, sizeof( mbedtls_aes_context ) );
if( aes == NULL )
return( NULL );
@ -510,7 +510,7 @@ static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
static void * camellia_ctx_alloc( void )
{
mbedtls_camellia_context *ctx;
ctx = mbedtls_malloc( sizeof( mbedtls_camellia_context ) );
ctx = mbedtls_calloc( 1, sizeof( mbedtls_camellia_context ) );
if( ctx == NULL )
return( NULL );
@ -897,7 +897,7 @@ static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
static void * des_ctx_alloc( void )
{
mbedtls_des_context *des = mbedtls_malloc( sizeof( mbedtls_des_context ) );
mbedtls_des_context *des = mbedtls_calloc( 1, sizeof( mbedtls_des_context ) );
if( des == NULL )
return( NULL );
@ -916,7 +916,7 @@ static void des_ctx_free( void *ctx )
static void * des3_ctx_alloc( void )
{
mbedtls_des3_context *des3;
des3 = mbedtls_malloc( sizeof( mbedtls_des3_context ) );
des3 = mbedtls_calloc( 1, sizeof( mbedtls_des3_context ) );
if( des3 == NULL )
return( NULL );
@ -1115,7 +1115,7 @@ static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
static void * blowfish_ctx_alloc( void )
{
mbedtls_blowfish_context *ctx;
ctx = mbedtls_malloc( sizeof( mbedtls_blowfish_context ) );
ctx = mbedtls_calloc( 1, sizeof( mbedtls_blowfish_context ) );
if( ctx == NULL )
return( NULL );
@ -1225,7 +1225,7 @@ static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
static void * arc4_ctx_alloc( void )
{
mbedtls_arc4_context *ctx;
ctx = mbedtls_malloc( sizeof( mbedtls_arc4_context ) );
ctx = mbedtls_calloc( 1, sizeof( mbedtls_arc4_context ) );
if( ctx == NULL )
return( NULL );