136 static unsigned long order = 0;
144 typedef struct app_mem_info_st
157 struct app_mem_info_st *next;
161 static void app_info_free(
APP_INFO *);
171 typedef struct mem_st
184 static long options =
185 #if defined(CRYPTO_MDEBUG_TIME) || defined(CRYPTO_MDEBUG_ALL)
188 #if defined(CRYPTO_MDEBUG_THREAD) || defined(CRYPTO_MDEBUG_ALL)
194 static unsigned int num_disable = 0;
204 static void app_info_free(
APP_INFO *inf)
206 if (--(inf->references) <= 0)
208 if (inf->next != NULL)
210 app_info_free(inf->next);
265 if (mh_mode & CRYPTO_MEM_CHECK_ON)
270 if (num_disable == 0)
315 static int mem_cmp(
const MEM *
a,
const MEM *
b)
318 const char *ap=(
const char *)a->addr,
319 *
bp=(
const char *)b->addr;
320 if (ap==
bp)
return 0;
321 else if (ap>
bp)
return 1;
324 return (
const char *)a->addr - (
const char *)b->addr;
329 static
unsigned long mem_hash(const
MEM *a)
333 ret=(
unsigned long)a->addr;
335 ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
341 static
int app_info_cmp(const
void *a_void, const
void *b_void)
344 &((
const APP_INFO *)b_void)->threadid);
348 static
unsigned long app_info_hash(const
APP_INFO *a)
354 ret=ret*17851+(ret>>14)*7+(ret>>4)*251;
376 #ifdef LEVITTE_DEBUG_MEM
379 fprintf(stderr,
"pop_info(): deleted info has other thread ID (%lu) than the current thread (%lu)!!!!\n",
385 if (--(ret->references) <= 0)
430 #ifdef LEVITTE_DEBUG_MEM
433 fprintf(stderr,
"CRYPTO_push_info(): previous info has other thread ID (%lu) than the current thread (%lu)!!!!\n",
456 ret=(pop_info() != NULL);
471 while(pop_info() != NULL)
480 static unsigned long break_order_num=0;
487 switch(before_p & 127)
523 memset(&m->threadid, 0,
sizeof(m->threadid));
525 if (order == break_order_num)
531 #ifdef LEVITTE_DEBUG_MEM
532 fprintf(stderr,
"LEVITTE_DEBUG_MEM: [%5ld] %c 0x%p (%d)\n",
534 (before_p & 128) ?
'*' :
'+',
554 if (mm->app_info != NULL)
556 mm->app_info->references--;
587 #ifdef LEVITTE_DEBUG_MEM
588 fprintf(stderr,
"LEVITTE_DEBUG_MEM: [%5ld] - 0x%p (%d)\n",
589 mp->order, mp->addr, mp->num);
591 if (mp->app_info != NULL)
592 app_info_free(mp->app_info);
606 const char *
file,
int line,
int before_p)
610 #ifdef LEVITTE_DEBUG_MEM
611 fprintf(stderr,
"LEVITTE_DEBUG_MEM: --> CRYPTO_dbg_malloc(addr1 = %p, addr2 = %p, num = %d, file = \"%s\", line = %d, before_p = %d)\n",
612 addr1, addr2, num, file, line, before_p);
637 #ifdef LEVITTE_DEBUG_MEM
638 fprintf(stderr,
"LEVITTE_DEBUG_MEM: [%5ld] * 0x%p (%d) -> 0x%p (%d)\n",
664 static void print_leak_doall_arg(
const MEM *m,
MEM_LEAK *l)
670 struct tm *lcl = NULL;
673 #define BUF_REMAIN (sizeof buf - (size_t)(bufp - buf))
675 if(m->addr == (
char *)l->
bio)
680 lcl = localtime(&m->time);
683 lcl->tm_hour,lcl->tm_min,lcl->tm_sec);
684 bufp += strlen(bufp);
687 BIO_snprintf(bufp, BUF_REMAIN,
"%5lu file=%s, line=%d, ",
688 m->order,m->file,m->line);
689 bufp += strlen(bufp);
695 bufp += strlen(bufp);
698 BIO_snprintf(bufp, BUF_REMAIN,
"number=%d, address=%08lX\n",
699 m->num,(
unsigned long)m->addr);
700 bufp += strlen(bufp);
719 memset(buf,
'>',ami_cnt);
721 " thread=%lu, file=%s, line=%d, info=\"",
725 info_len=strlen(amip->info);
726 if (128 - buf_len - 3 < info_len)
728 memcpy(buf + buf_len, amip->info, 128 - buf_len - 3);
734 sizeof buf - buf_len);
735 buf_len = strlen(buf);
737 BIO_snprintf(buf + buf_len,
sizeof buf - buf_len,
"\"\n");
745 #ifdef LEVITTE_DEBUG_MEM
748 fprintf(stderr,
"Thread switch detected in backtrace!!!!\n");
760 if (mh == NULL && amih == NULL)
773 BIO_printf(b,
"%ld bytes leaked in %d chunks\n",
775 #ifdef CRYPTO_MDEBUG_ABORT
802 old_mh_mode = mh_mode;
819 mh_mode = old_mh_mode;
825 #ifndef OPENSSL_NO_FP_API
830 if (mh == NULL)
return;
860 static void cb_leak_doall_arg(
const MEM *m, PCRYPTO_MEM_LEAK_CB *
cb)
862 (*cb)(m->order,m->file,m->line,m->num,m->addr);
869 if (mh == NULL)
return;