X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=crypto%2Fmem_dbg.c;h=fb1fdd7453f60d405733d7a9bb424cbe4f0834f4;hb=eddf82a36a8039af7bd16947aca66e2c7fa64e0a;hp=61329b098d8d89729df314ae6c60af055b293cab;hpb=fe8686ba4b359026f7d077b6f17faa698d08b297;p=oweals%2Fopenssl.git diff --git a/crypto/mem_dbg.c b/crypto/mem_dbg.c index 61329b098d..fb1fdd7453 100644 --- a/crypto/mem_dbg.c +++ b/crypto/mem_dbg.c @@ -219,31 +219,37 @@ long CRYPTO_dbg_get_options(void) return options; } -static int mem_cmp(MEM *a, MEM *b) +/* static int mem_cmp(MEM *a, MEM *b) */ +static int mem_cmp(const void *a_void, const void *b_void) { - return((char *)a->addr - (char *)b->addr); + return((const char *)((MEM *)a_void)->addr + - (const char *)((MEM *)b_void)->addr); } -static unsigned long mem_hash(MEM *a) +/* static unsigned long mem_hash(MEM *a) */ +static unsigned long mem_hash(const void *a_void) { unsigned long ret; - ret=(unsigned long)a->addr; + ret=(unsigned long)((const MEM *)a_void)->addr; ret=ret*17851+(ret>>14)*7+(ret>>4)*251; return(ret); } -static int app_info_cmp(APP_INFO *a, APP_INFO *b) +/* static int app_info_cmp(APP_INFO *a, APP_INFO *b) */ +static int app_info_cmp(const void *a_void, const void *b_void) { - return(a->thread != b->thread); + return(((const APP_INFO *)a_void)->thread + != ((const APP_INFO *)b_void)->thread); } -static unsigned long app_info_hash(APP_INFO *a) +/* static unsigned long app_info_hash(APP_INFO *a) */ +static unsigned long app_info_hash(const void *a_void) { unsigned long ret; - ret=(unsigned long)a->thread; + ret=(unsigned long)((const APP_INFO *)a_void)->thread; ret=ret*17851+(ret>>14)*7+(ret>>4)*251; return(ret); @@ -302,7 +308,7 @@ int CRYPTO_push_info_(const char *info, const char *file, int line) } if (amih == NULL) { - if ((amih=lh_new(app_info_hash,app_info_cmp)) == NULL) + if ((amih=lh_new(app_info_hash, app_info_cmp)) == NULL) { OPENSSL_free(ami); ret=0; @@ -394,7 +400,7 @@ void CRYPTO_dbg_malloc(void *addr, int num, const char *file, int line, } if (mh == NULL) { - if ((mh=lh_new(mem_hash,mem_cmp)) == NULL) + if ((mh=lh_new(mem_hash, mem_cmp)) == NULL) { OPENSSL_free(addr); OPENSSL_free(m); @@ -635,6 +641,8 @@ static void print_leak(MEM *m, MEM_LEAK *l) #endif } +static IMPLEMENT_LHASH_DOALL_ARG_FN(print_leak, MEM *, MEM_LEAK *) + void CRYPTO_mem_leaks(BIO *b) { MEM_LEAK ml; @@ -647,7 +655,8 @@ void CRYPTO_mem_leaks(BIO *b) ml.chunks=0; MemCheck_off(); /* obtains CRYPTO_LOCK_MALLOC2 */ if (mh != NULL) - lh_doall_arg(mh,(void (*)())print_leak,(char *)&ml); + lh_doall_arg(mh, LHASH_DOALL_ARG_FN(print_leak), + (char *)&ml); if (ml.chunks != 0) { sprintf(buf,"%ld bytes leaked in %d chunks\n", @@ -671,7 +680,15 @@ void CRYPTO_mem_leaks(BIO *b) * void_fn_to_char kludge in CRYPTO_mem_leaks_cb. * Otherwise the code police will come and get us.) */ + int old_mh_mode; + CRYPTO_w_lock(CRYPTO_LOCK_MALLOC); + + /* avoid deadlock when lh_free() uses CRYPTO_dbg_free(), + * which uses CRYPTO_is_mem_check_on */ + old_mh_mode = mh_mode; + mh_mode = CRYPTO_MEM_CHECK_OFF; + if (mh != NULL) { lh_free(mh); @@ -685,6 +702,8 @@ void CRYPTO_mem_leaks(BIO *b) amih = NULL; } } + + mh_mode = old_mh_mode; CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC); } MemCheck_on(); /* releases CRYPTO_LOCK_MALLOC2 */ @@ -715,16 +734,20 @@ void CRYPTO_mem_leaks_fp(FILE *fp) /* FIXME: We really don't allow much to the callback. For example, it has no chance of reaching the info stack for the item it processes. Should it really be this way? -- Richard Levitte */ -static void cb_leak(MEM *m, - void (**cb)(unsigned long, const char *, int, int, void *)) +/* NB: The prototypes have been typedef'd to CRYPTO_MEM_LEAK_CB inside crypto.h + * If this code is restructured, remove the callback type if it is no longer + * needed. -- Geoff Thorpe */ +static void cb_leak(MEM *m, CRYPTO_MEM_LEAK_CB *cb) { (**cb)(m->order,m->file,m->line,m->num,m->addr); } -void CRYPTO_mem_leaks_cb(void (*cb)(unsigned long, const char *, int, int, void *)) +static IMPLEMENT_LHASH_DOALL_ARG_FN(cb_leak, MEM *, CRYPTO_MEM_LEAK_CB *) + +void CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB cb) { if (mh == NULL) return; CRYPTO_w_lock(CRYPTO_LOCK_MALLOC2); - lh_doall_arg(mh,(void (*)())cb_leak,(void *)&cb); + lh_doall_arg(mh, LHASH_DOALL_ARG_FN(cb_leak), &cb); CRYPTO_w_unlock(CRYPTO_LOCK_MALLOC2); }