diff options
-rw-r--r-- | src/common/crypto.c | 12 | ||||
-rw-r--r-- | src/common/crypto.h | 4 | ||||
-rw-r--r-- | src/or/main.c | 5 | ||||
-rw-r--r-- | src/test/testing_common.c | 5 |
4 files changed, 20 insertions, 6 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c index a5eb7b5c9a..e1094aec50 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -3459,3 +3459,15 @@ crypto_global_cleanup(void) /** @} */ +#ifdef USE_DMALLOC +/** Tell the crypto library to use Tor's allocation functions rather than + * calling libc's allocation functions directly. Return 0 on success, -1 + * on failure. */ +int +crypto_use_tor_alloc_functions(void) +{ + int r = CRYPTO_set_mem_ex_functions(tor_malloc_, tor_realloc_, tor_free_); + return r ? 0 : -1; +} +#endif + diff --git a/src/common/crypto.h b/src/common/crypto.h index 62c78b5d77..c70d91c262 100644 --- a/src/common/crypto.h +++ b/src/common/crypto.h @@ -131,6 +131,10 @@ int crypto_early_init(void) ATTR_WUR; int crypto_global_init(int hardwareAccel, const char *accelName, const char *accelPath) ATTR_WUR; +#ifdef USE_DMALLOC +int crypto_use_tor_alloc_functions(void); +#endif + void crypto_thread_cleanup(void); int crypto_global_cleanup(void); diff --git a/src/or/main.c b/src/or/main.c index 5b73aea70c..4505879adc 100644 --- a/src/or/main.c +++ b/src/or/main.c @@ -104,7 +104,6 @@ #include "ext_orport.h" #ifdef USE_DMALLOC #include <dmalloc.h> -#include <openssl/crypto.h> #endif #include "memarea.h" #include "sandbox.h" @@ -3617,8 +3616,8 @@ tor_main(int argc, char *argv[]) { /* Instruct OpenSSL to use our internal wrappers for malloc, realloc and free. */ - int r = CRYPTO_set_mem_ex_functions(tor_malloc_, tor_realloc_, tor_free_); - tor_assert(r); + int r = crypto_use_tor_alloc_functions(); + tor_assert(r == 0); } #endif #ifdef NT_SERVICE diff --git a/src/test/testing_common.c b/src/test/testing_common.c index bb2bcbf44c..0e37e0d154 100644 --- a/src/test/testing_common.c +++ b/src/test/testing_common.c @@ -38,7 +38,6 @@ const char tor_git_revision[] = ""; #ifdef USE_DMALLOC #include <dmalloc.h> -#include <openssl/crypto.h> #include "main.h" #endif @@ -238,8 +237,8 @@ main(int c, const char **v) #ifdef USE_DMALLOC { - int r = CRYPTO_set_mem_ex_functions(tor_malloc_, tor_realloc_, tor_free_); - tor_assert(r); + int r = crypto_use_tor_alloc_functions(); + tor_assert(r == 0); } #endif |