diff options
author | Rich Salz <rsalz@akamai.com> | 2019-07-10 16:22:12 -0400 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2019-07-17 14:48:06 +0200 |
commit | e7aa7c11c71e84b2d6c06b1c81d130e8c1fba296 (patch) | |
tree | 78fdf15ffe34aea243fa53fd2bb389653dc4bde6 /crypto/mem_dbg.c | |
parent | 7bc82358ae930cfbd353602bc1fd25bfad107350 (diff) |
Deprecated {OPENSSL,CRYPTO}_debug_mem_{push,pop}
They were only used for recursive ASN1 parsing.
Even if the internal memory-debugging facility remains,
this simplification seems worthwhile.
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9342)
Diffstat (limited to 'crypto/mem_dbg.c')
-rw-r--r-- | crypto/mem_dbg.c | 169 |
1 files changed, 6 insertions, 163 deletions
diff --git a/crypto/mem_dbg.c b/crypto/mem_dbg.c index 8fcdbeca9e..3b1e37f301 100644 --- a/crypto/mem_dbg.c +++ b/crypto/mem_dbg.c @@ -39,26 +39,9 @@ static int mh_mode = CRYPTO_MEM_CHECK_OFF; #ifndef OPENSSL_NO_CRYPTO_MDEBUG static unsigned long order = 0; /* number of memory requests */ -/*- - * For application-defined information (static C-string `info') - * to be displayed in memory leak list. - * Each thread has its own stack. For applications, there is - * OPENSSL_mem_debug_push("...") to push an entry, - * OPENSSL_mem_debug_pop() to pop an entry, - */ -struct app_mem_info_st { - CRYPTO_THREAD_ID threadid; - const char *file; - int line; - const char *info; - struct app_mem_info_st *next; /* tail of thread's stack */ - int references; -}; - static CRYPTO_ONCE memdbg_init = CRYPTO_ONCE_STATIC_INIT; CRYPTO_RWLOCK *memdbg_lock; static CRYPTO_RWLOCK *long_memdbg_lock; -static CRYPTO_THREAD_LOCAL appinfokey; /* memory-block description */ struct mem_st { @@ -69,7 +52,6 @@ struct mem_st { CRYPTO_THREAD_ID threadid; unsigned long order; time_t time; - APP_INFO *app_info; #ifndef OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE void *array[30]; size_t array_siz; @@ -95,8 +77,7 @@ DEFINE_RUN_ONCE_STATIC(do_memdbg_init) { memdbg_lock = CRYPTO_THREAD_lock_new(); long_memdbg_lock = CRYPTO_THREAD_lock_new(); - if (memdbg_lock == NULL || long_memdbg_lock == NULL - || !CRYPTO_THREAD_init_local(&appinfokey, NULL)) { + if (memdbg_lock == NULL || long_memdbg_lock == NULL) { CRYPTO_THREAD_lock_free(memdbg_lock); memdbg_lock = NULL; CRYPTO_THREAD_lock_free(long_memdbg_lock); @@ -106,15 +87,6 @@ DEFINE_RUN_ONCE_STATIC(do_memdbg_init) return 1; } -static void app_info_free(APP_INFO *inf) -{ - if (inf == NULL) - return; - if (--(inf->references) <= 0) { - app_info_free(inf->next); - OPENSSL_free(inf); - } -} #endif int CRYPTO_mem_ctrl(int mode) @@ -237,77 +209,14 @@ static unsigned long mem_hash(const MEM *a) return ret; } -/* returns 1 if there was an info to pop, 0 if the stack was empty. */ -static int pop_info(void) -{ - APP_INFO *current = NULL; - - if (!RUN_ONCE(&memdbg_init, do_memdbg_init)) - return 0; - - current = (APP_INFO *)CRYPTO_THREAD_get_local(&appinfokey); - if (current != NULL) { - APP_INFO *next = current->next; - - if (next != NULL) { - next->references++; - CRYPTO_THREAD_set_local(&appinfokey, next); - } else { - CRYPTO_THREAD_set_local(&appinfokey, NULL); - } - if (--(current->references) <= 0) { - current->next = NULL; - if (next != NULL) - next->references--; - OPENSSL_free(current); - } - return 1; - } - return 0; -} - int CRYPTO_mem_debug_push(const char *info, const char *file, int line) { - APP_INFO *ami, *amim; - int ret = 0; - - if (mem_check_on()) { - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); - - if (!RUN_ONCE(&memdbg_init, do_memdbg_init) - || (ami = OPENSSL_malloc(sizeof(*ami))) == NULL) - goto err; - - ami->threadid = CRYPTO_THREAD_get_current_id(); - ami->file = file; - ami->line = line; - ami->info = info; - ami->references = 1; - ami->next = NULL; - - amim = (APP_INFO *)CRYPTO_THREAD_get_local(&appinfokey); - CRYPTO_THREAD_set_local(&appinfokey, ami); - - if (amim != NULL) - ami->next = amim; - ret = 1; - err: - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); - } - - return ret; + return 0; } int CRYPTO_mem_debug_pop(void) { - int ret = 0; - - if (mem_check_on()) { - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); - ret = pop_info(); - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); - } - return ret; + return 0; } static unsigned long break_order_num = 0; @@ -316,7 +225,6 @@ void CRYPTO_mem_debug_malloc(void *addr, size_t num, int before_p, const char *file, int line) { MEM *m, *mm; - APP_INFO *amim; switch (before_p & 127) { case 0: @@ -359,18 +267,8 @@ void CRYPTO_mem_debug_malloc(void *addr, size_t num, int before_p, # endif m->time = time(NULL); - amim = (APP_INFO *)CRYPTO_THREAD_get_local(&appinfokey); - m->app_info = amim; - if (amim != NULL) - amim->references++; - - if ((mm = lh_MEM_insert(mh, m)) != NULL) { - /* Not good, but don't sweat it */ - if (mm->app_info != NULL) { - mm->app_info->references--; - } + if ((mm = lh_MEM_insert(mh, m)) != NULL) OPENSSL_free(mm); - } err: CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); } @@ -391,14 +289,9 @@ void CRYPTO_mem_debug_free(void *addr, int before_p, if (mem_check_on() && (mh != NULL)) { CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); - m.addr = addr; mp = lh_MEM_delete(mh, &m); - if (mp != NULL) { - app_info_free(mp->app_info); - OPENSSL_free(mp); - } - + OPENSSL_free(mp); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); } break; @@ -456,11 +349,9 @@ static void print_leak(const MEM *m, MEM_LEAK *l) { char buf[1024]; char *bufp = buf, *hex; - size_t len = sizeof(buf), ami_cnt; - APP_INFO *amip; + size_t len = sizeof(buf); int n; struct tm *lcl = NULL; - CRYPTO_THREAD_ID ti; lcl = localtime(&m->time); n = BIO_snprintf(bufp, len, "[%02d:%02d:%02d] ", @@ -490,56 +381,9 @@ static void print_leak(const MEM *m, MEM_LEAK *l) len -= n; l->print_cb(buf, (size_t)(bufp - buf), l->print_cb_arg); - l->chunks++; l->bytes += m->num; - amip = m->app_info; - ami_cnt = 0; - - if (amip) { - ti = amip->threadid; - - do { - int buf_len; - int info_len; - - ami_cnt++; - if (ami_cnt >= sizeof(buf) - 1) - break; - memset(buf, '>', ami_cnt); - buf[ami_cnt] = '\0'; - hex = OPENSSL_buf2hexstr((const unsigned char *)&amip->threadid, - sizeof(amip->threadid)); - n = BIO_snprintf(buf + ami_cnt, sizeof(buf) - ami_cnt, - "thread=%s, file=%s, line=%d, info=\"", - hex, amip->file, amip->line); - OPENSSL_free(hex); - if (n <= 0) - break; - buf_len = ami_cnt + n; - info_len = strlen(amip->info); - if (128 - buf_len - 3 < info_len) { - memcpy(buf + buf_len, amip->info, 128 - buf_len - 3); - buf_len = 128 - 3; - } else { - n = BIO_snprintf(buf + buf_len, sizeof(buf) - buf_len, "%s", - amip->info); - if (n < 0) - break; - buf_len += n; - } - n = BIO_snprintf(buf + buf_len, sizeof(buf) - buf_len, "\"\n"); - if (n <= 0) - break; - - l->print_cb(buf, buf_len + n, l->print_cb_arg); - - amip = amip->next; - } - while (amip && CRYPTO_THREAD_compare_id(amip->threadid, ti)); - } - #ifndef OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE { size_t i; @@ -607,7 +451,6 @@ int CRYPTO_mem_leaks_cb(int (*cb) (const char *str, size_t len, void *u), CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF); /* Clean up locks etc */ - CRYPTO_THREAD_cleanup_local(&appinfokey); CRYPTO_THREAD_lock_free(memdbg_lock); CRYPTO_THREAD_lock_free(long_memdbg_lock); memdbg_lock = NULL; |