-#include "cryptlib.h"
-
-
-static char *(*malloc_locked_func)()=(char *(*)())malloc;
-static void (*free_locked_func)()=(void (*)())free;
-static char *(*malloc_func)()= (char *(*)())malloc;
-static char *(*realloc_func)()= (char *(*)())realloc;
-static void (*free_func)()= (void (*)())free;
-
-static void (*malloc_debug_func)()= (void (*)())CRYPTO_dbg_malloc;
-static void (*realloc_debug_func)()= (void (*)())CRYPTO_dbg_realloc;
-static void (*free_debug_func)()= (void (*)())CRYPTO_dbg_free;
-static void (*set_debug_options_func)()= (void (*)())CRYPTO_dbg_set_options;
-static int (*get_debug_options_func)()= (int (*)())CRYPTO_dbg_get_options;
-
-void CRYPTO_set_mem_functions(char *(*m)(), char *(*r)(), void (*f)())
- {
- if ((m == NULL) || (r == NULL) || (f == NULL)) return;
- malloc_func=m;
- realloc_func=r;
- free_func=f;
- malloc_locked_func=m;
- free_locked_func=f;
- }
-
-void CRYPTO_set_mem_debug_functions(void (*m)(), void (*r)(), void (*f)(),void (*so)(),int (*go)())
- {
- if ((m == NULL) || (r == NULL) || (f == NULL) || (so == NULL) || (go == NULL))
- return;
- malloc_debug_func=m;
- realloc_debug_func=r;
- free_debug_func=f;
- set_debug_options_func=so;
- get_debug_options_func=go;
- }
-
-void CRYPTO_set_locked_mem_functions(char *(*m)(), void (*f)())
- {
- if ((m == NULL) || (f == NULL)) return;
- malloc_locked_func=m;
- free_locked_func=f;
- }
-
-void CRYPTO_get_mem_functions(char *(**m)(), char *(**r)(), void (**f)())
- {
- if (m != NULL) *m=malloc_func;
- if (r != NULL) *r=realloc_func;
- if (f != NULL) *f=free_func;
- }
-
-void CRYPTO_get_mem_debug_functions(void (**m)(), void (**r)(), void (**f)(),void (**so)(),int (**go)())
- {
- if (m != NULL) *m=malloc_debug_func;
- if (r != NULL) *r=realloc_debug_func;
- if (f != NULL) *f=free_debug_func;
- if (so != NULL) *so=set_debug_options_func;
- if (go != NULL) *go=get_debug_options_func;
- }
-
-void CRYPTO_get_locked_mem_functions(char *(**m)(), void (**f)())
- {
- if (m != NULL) *m=malloc_locked_func;
- if (f != NULL) *f=free_locked_func;
- }
-
-void *CRYPTO_malloc_locked(int num, char *file, int line)
- {
- char *ret = NULL;
-
- malloc_debug_func(NULL, num, file, line, 0);
- ret = malloc_locked_func(num);
-#ifdef LEVITTE_DEBUG
- fprintf(stderr, "LEVITTE_DEBUG: > 0x%p (%d)\n", ret, num);
+#include "internal/cryptlib.h"
+
+/*
+ * the following pointers may be changed as long as 'allow_customize' is set
+ */
+static int allow_customize = 1;
+
+static void *(*malloc_wrapper)(size_t, const char *, int)
+ = CRYPTO_malloc;
+static void *(*realloc_wrapper)(void *, size_t, const char *, int)
+ = CRYPTO_realloc;
+static void (*free_wrapper)(void *)
+ = CRYPTO_free;
+
+#ifdef CRYPTO_MDEBUG
+static int call_malloc_debug = 1;
+#else
+static int call_malloc_debug = 0;