diff options
author | Richard Levitte <levitte@openssl.org> | 2016-07-19 20:42:11 +0300 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2016-07-20 00:49:54 +0300 |
commit | c2e4e5d248567d4eea5bf6d525bdbcc09099ba6e (patch) | |
tree | e4e16df15de0263a21427c92ae21d20dc98e3c19 /crypto/mem_dbg.c | |
parent | 925d17f3ee4b7f7881fa77a31524ecd9f1305242 (diff) |
Change all our uses of CRYPTO_THREAD_run_once to use RUN_ONCE instead
That way, we have a way to check if the init function was successful
or not.
Reviewed-by: Kurt Roeckx <kurt@openssl.org>
Diffstat (limited to 'crypto/mem_dbg.c')
-rw-r--r-- | crypto/mem_dbg.c | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/crypto/mem_dbg.c b/crypto/mem_dbg.c index 0b48708232..0307c02517 100644 --- a/crypto/mem_dbg.c +++ b/crypto/mem_dbg.c @@ -112,7 +112,8 @@ int CRYPTO_mem_ctrl(int mode) #else int ret = mh_mode; - CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init); + if (!RUN_ONCE(&memdbg_init, do_memdbg_init)) + return -1; CRYPTO_THREAD_write_lock(malloc_lock); switch (mode) { @@ -185,7 +186,8 @@ static int mem_check_on(void) CRYPTO_THREAD_ID cur; if (mh_mode & CRYPTO_MEM_CHECK_ON) { - CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init); + if (!RUN_ONCE(&memdbg_init, do_memdbg_init)) + return 0; cur = CRYPTO_THREAD_get_current_id(); CRYPTO_THREAD_read_lock(malloc_lock); @@ -228,7 +230,9 @@ static int pop_info(void) { APP_INFO *current = NULL; - CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init); + 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; @@ -258,9 +262,8 @@ int CRYPTO_mem_debug_push(const char *info, const char *file, int line) if (mem_check_on()) { CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); - CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init); - - if ((ami = OPENSSL_malloc(sizeof(*ami))) == NULL) + if (!RUN_ONCE(&memdbg_init, do_memdbg_init) + || (ami = OPENSSL_malloc(sizeof(*ami))) == NULL) goto err; ami->threadid = CRYPTO_THREAD_get_current_id(); @@ -313,9 +316,8 @@ void CRYPTO_mem_debug_malloc(void *addr, size_t num, int before_p, if (mem_check_on()) { CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); - CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init); - - if ((m = OPENSSL_malloc(sizeof(*m))) == NULL) { + if (!RUN_ONCE(&memdbg_init, do_memdbg_init) + || (m = OPENSSL_malloc(sizeof(*m))) == NULL) { OPENSSL_free(addr); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); return; @@ -543,7 +545,8 @@ int CRYPTO_mem_leaks(BIO *b) /* Ensure all resources are released */ OPENSSL_cleanup(); - CRYPTO_THREAD_run_once(&memdbg_init, do_memdbg_init); + if (!RUN_ONCE(&memdbg_init, do_memdbg_init)) + return -1; CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); |