mirror of
https://github.com/MariaDB/server.git
synced 2025-08-08 11:22:35 +03:00
Framework to simplify memory leak tracing
This commit is contained in:
@@ -44,9 +44,10 @@ typedef struct st_hash {
|
|||||||
uint (*calc_hashnr)(const byte *key,uint length);
|
uint (*calc_hashnr)(const byte *key,uint length);
|
||||||
} HASH;
|
} HASH;
|
||||||
|
|
||||||
my_bool hash_init(HASH *hash,uint default_array_elements, uint key_offset,
|
#define hash_init(A,B,C,D,E,F,G) _hash_init(A,B,C,D,E,F,G CALLER_INFO)
|
||||||
|
my_bool _hash_init(HASH *hash,uint default_array_elements, uint key_offset,
|
||||||
uint key_length, hash_get_key get_key,
|
uint key_length, hash_get_key get_key,
|
||||||
void (*free_element)(void*), uint flags);
|
void (*free_element)(void*), uint flags CALLER_INFO_PROTO);
|
||||||
void hash_free(HASH *tree);
|
void hash_free(HASH *tree);
|
||||||
byte *hash_element(HASH *hash,uint idx);
|
byte *hash_element(HASH *hash,uint idx);
|
||||||
gptr hash_search(HASH *info,const byte *key,uint length);
|
gptr hash_search(HASH *info,const byte *key,uint length);
|
||||||
|
@@ -115,6 +115,7 @@ extern int NEAR my_errno; /* Last error in mysys */
|
|||||||
|
|
||||||
#ifdef SAFEMALLOC
|
#ifdef SAFEMALLOC
|
||||||
#define my_malloc(SZ,FLAG) _mymalloc( SZ, __FILE__, __LINE__, FLAG )
|
#define my_malloc(SZ,FLAG) _mymalloc( SZ, __FILE__, __LINE__, FLAG )
|
||||||
|
#define my_malloc_ci(SZ,FLAG) _mymalloc( SZ, sFile, uLine, FLAG )
|
||||||
#define my_realloc(PTR,SZ,FLAG) _myrealloc( PTR, SZ, __FILE__, __LINE__, FLAG )
|
#define my_realloc(PTR,SZ,FLAG) _myrealloc( PTR, SZ, __FILE__, __LINE__, FLAG )
|
||||||
#define my_checkmalloc() _sanity( __FILE__, __LINE__ )
|
#define my_checkmalloc() _sanity( __FILE__, __LINE__ )
|
||||||
#define my_free(PTR,FLAG) _myfree( PTR, __FILE__, __LINE__,FLAG)
|
#define my_free(PTR,FLAG) _myfree( PTR, __FILE__, __LINE__,FLAG)
|
||||||
@@ -124,6 +125,9 @@ extern int NEAR my_errno; /* Last error in mysys */
|
|||||||
#define NORMAL_SAFEMALLOC sf_malloc_quick=0
|
#define NORMAL_SAFEMALLOC sf_malloc_quick=0
|
||||||
extern uint sf_malloc_prehunc,sf_malloc_endhunc,sf_malloc_quick;
|
extern uint sf_malloc_prehunc,sf_malloc_endhunc,sf_malloc_quick;
|
||||||
extern ulonglong safemalloc_mem_limit;
|
extern ulonglong safemalloc_mem_limit;
|
||||||
|
#define CALLER_INFO_PROTO , const char *sFile, uint uLine
|
||||||
|
#define CALLER_INFO , __FILE__, __LINE__
|
||||||
|
#define ORIG_CALLER_INFO , sFile, uLine
|
||||||
#else
|
#else
|
||||||
#define my_checkmalloc() (0)
|
#define my_checkmalloc() (0)
|
||||||
#undef TERMINATE
|
#undef TERMINATE
|
||||||
@@ -131,11 +135,15 @@ extern ulonglong safemalloc_mem_limit;
|
|||||||
#define QUICK_SAFEMALLOC
|
#define QUICK_SAFEMALLOC
|
||||||
#define NORMAL_SAFEMALLOC
|
#define NORMAL_SAFEMALLOC
|
||||||
extern gptr my_malloc(uint Size,myf MyFlags);
|
extern gptr my_malloc(uint Size,myf MyFlags);
|
||||||
|
#define my_malloc_ci(SZ,FLAG) my_malloc( SZ, FLAG )
|
||||||
extern gptr my_realloc(gptr oldpoint,uint Size,myf MyFlags);
|
extern gptr my_realloc(gptr oldpoint,uint Size,myf MyFlags);
|
||||||
extern void my_no_flags_free(gptr ptr);
|
extern void my_no_flags_free(gptr ptr);
|
||||||
extern gptr my_memdup(const byte *from,uint length,myf MyFlags);
|
extern gptr my_memdup(const byte *from,uint length,myf MyFlags);
|
||||||
extern my_string my_strdup(const char *from,myf MyFlags);
|
extern my_string my_strdup(const char *from,myf MyFlags);
|
||||||
#define my_free(PTR,FG) my_no_flags_free(PTR)
|
#define my_free(PTR,FG) my_no_flags_free(PTR)
|
||||||
|
#define CALLER_INFO_PROTO /* nothing */
|
||||||
|
#define CALLER_INFO /* nothing */
|
||||||
|
#define ORIG_CALLER_INFO /* nothing */
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_ALLOCA
|
#ifdef HAVE_ALLOCA
|
||||||
#define my_alloca(SZ) alloca((size_t) (SZ))
|
#define my_alloca(SZ) alloca((size_t) (SZ))
|
||||||
@@ -541,8 +549,10 @@ extern my_bool real_open_cached_file(IO_CACHE *cache);
|
|||||||
extern void close_cached_file(IO_CACHE *cache);
|
extern void close_cached_file(IO_CACHE *cache);
|
||||||
File create_temp_file(char *to, const char *dir, const char *pfx,
|
File create_temp_file(char *to, const char *dir, const char *pfx,
|
||||||
int mode, myf MyFlags);
|
int mode, myf MyFlags);
|
||||||
extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size,
|
#define init_dynamic_array(A,B,C,D) _init_dynamic_array(A,B,C,D CALLER_INFO)
|
||||||
uint init_alloc,uint alloc_increment);
|
#define init_dynamic_array_ci(A,B,C,D) _init_dynamic_array(A,B,C,D ORIG_CALLER_INFO)
|
||||||
|
extern my_bool _init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size,
|
||||||
|
uint init_alloc,uint alloc_increment CALLER_INFO_PROTO);
|
||||||
extern my_bool insert_dynamic(DYNAMIC_ARRAY *array,gptr element);
|
extern my_bool insert_dynamic(DYNAMIC_ARRAY *array,gptr element);
|
||||||
extern byte *alloc_dynamic(DYNAMIC_ARRAY *array);
|
extern byte *alloc_dynamic(DYNAMIC_ARRAY *array);
|
||||||
extern byte *pop_dynamic(DYNAMIC_ARRAY*);
|
extern byte *pop_dynamic(DYNAMIC_ARRAY*);
|
||||||
|
@@ -29,8 +29,8 @@
|
|||||||
even if space allocation failed
|
even if space allocation failed
|
||||||
*/
|
*/
|
||||||
|
|
||||||
my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size,
|
my_bool _init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size,
|
||||||
uint init_alloc, uint alloc_increment)
|
uint init_alloc, uint alloc_increment CALLER_INFO_PROTO)
|
||||||
{
|
{
|
||||||
DBUG_ENTER("init_dynamic_array");
|
DBUG_ENTER("init_dynamic_array");
|
||||||
if (!alloc_increment)
|
if (!alloc_increment)
|
||||||
@@ -46,7 +46,7 @@ my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size,
|
|||||||
array->max_element=init_alloc;
|
array->max_element=init_alloc;
|
||||||
array->alloc_increment=alloc_increment;
|
array->alloc_increment=alloc_increment;
|
||||||
array->size_of_element=element_size;
|
array->size_of_element=element_size;
|
||||||
if (!(array->buffer=(char*) my_malloc(element_size*init_alloc,MYF(MY_WME))))
|
if (!(array->buffer=(char*) my_malloc_ci(element_size*init_alloc,MYF(MY_WME))))
|
||||||
{
|
{
|
||||||
array->max_element=0;
|
array->max_element=0;
|
||||||
DBUG_RETURN(TRUE);
|
DBUG_RETURN(TRUE);
|
||||||
|
@@ -37,15 +37,15 @@ static uint calc_hashnr_caseup(const byte *key,uint length);
|
|||||||
static int hashcmp(HASH *hash,HASH_LINK *pos,const byte *key,uint length);
|
static int hashcmp(HASH *hash,HASH_LINK *pos,const byte *key,uint length);
|
||||||
|
|
||||||
|
|
||||||
my_bool hash_init(HASH *hash,uint size,uint key_offset,uint key_length,
|
my_bool _hash_init(HASH *hash,uint size,uint key_offset,uint key_length,
|
||||||
hash_get_key get_key,
|
hash_get_key get_key,
|
||||||
void (*free_element)(void*),uint flags)
|
void (*free_element)(void*),uint flags CALLER_INFO_PROTO)
|
||||||
{
|
{
|
||||||
DBUG_ENTER("hash_init");
|
DBUG_ENTER("hash_init");
|
||||||
DBUG_PRINT("enter",("hash: %lx size: %d",hash,size));
|
DBUG_PRINT("enter",("hash: %lx size: %d",hash,size));
|
||||||
|
|
||||||
hash->records=0;
|
hash->records=0;
|
||||||
if (init_dynamic_array(&hash->array,sizeof(HASH_LINK),size,0))
|
if (init_dynamic_array_ci(&hash->array,sizeof(HASH_LINK),size,0))
|
||||||
{
|
{
|
||||||
hash->free=0; /* Allow call to hash_free */
|
hash->free=0; /* Allow call to hash_free */
|
||||||
DBUG_RETURN(TRUE);
|
DBUG_RETURN(TRUE);
|
||||||
|
Reference in New Issue
Block a user