]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Isolate dmalloc/openssl bridge code to crypto.c
authorNick Mathewson <nickm@torproject.org>
Sat, 25 Mar 2017 10:27:50 +0000 (11:27 +0100)
committerNick Mathewson <nickm@torproject.org>
Fri, 31 Mar 2017 14:04:44 +0000 (10:04 -0400)
This makes it so main.c, and the rest of src/or, no longer need to
include any openssl headers.

src/common/crypto.c
src/common/crypto.h
src/or/main.c
src/test/testing_common.c

index a5eb7b5c9a322507c68cda24ee1b956a49becf5b..e1094aec501053695dd8b60d0ce34374a8d85af5 100644 (file)
@@ -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
+
index 62c78b5d77e33d0cca9b18b333185ff4a38dfd48..c70d91c262bf2470ab06d3d5ec7e2bb3010ae8b7 100644 (file)
@@ -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);
 
index 5b73aea70ce91115e2ce0a7ec9f87848deeea85b..4505879adcbf429d1e21aa0da3764c10e8f7283a 100644 (file)
 #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
index bb2bcbf44cf51a12d84556bf8b8ad158af9d0d7b..0e37e0d15491b073a967a8917f3da48563c64a3d 100644 (file)
@@ -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