メモリリーク対策、HSM関連のアロケータを自前で用意

git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@138 ff987cc8-cf2f-4642-8568-d52cce064691
This commit is contained in:
kubodera_yuichi 2010-01-06 00:45:24 +00:00
parent b6844a8b69
commit 5a1ea7706f
3 changed files with 18 additions and 1 deletions

View File

@ -17,6 +17,10 @@
/* --------------------- */
static int alloc_counter = 0;
/* --------------------- */
const NFast_MallocUpcalls my_hsm_malloc_upcalls =
{
my_hsm_malloc, my_hsm_realloc, my_hsm_free
@ -27,6 +31,7 @@ const NFast_MallocUpcalls my_hsm_malloc_upcalls =
void *my_hsm_malloc( size_t nbytes,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx )
{
alloc_counter++;
return malloc( nbytes );
}
@ -44,6 +49,14 @@ void my_hsm_free( void *ptr,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx )
{
free( ptr );
alloc_counter--;
}
/* --------------------- */
int my_hsm_get_alloc_counter( void )
{
return alloc_counter;
}
#endif // HSM

View File

@ -22,6 +22,8 @@ void *my_hsm_realloc( void *ptr, size_t nbytes,
void my_hsm_free( void *ptr,
struct NFast_Call_Context *cctx, struct NFast_Transaction_Context *tctx );
int my_hsm_get_alloc_counter( void );
#ifdef __cplusplus
}
#endif

View File

@ -119,6 +119,7 @@
#ifdef USE_HSM
#include "cr_hsm_code.h"
#include "cr_hsm_alloc.h"
#include "cr_hsm_bignum.h"
#include "cr_generate_id.h"
#include "cr_generate_id_private.h"
@ -179,7 +180,8 @@ int hsm_initialize( void )
#endif
// init HSM
ret_code = NFastApp_InitEx( &hsmHandle, NULL, NULL );
ret_code = NFastApp_Init( &hsmHandle, my_hsm_alloc, my_hsm_realloc, my_hsm_free, NULL );
//ret_code = NFastApp_InitEx( &hsmHandle, NULL, NULL );
if ( ret_code != CR_GENID_SUCCESS )
{
SetErrorInfo( __FUNCTION__, __LINE__ );