summaryrefslogtreecommitdiffstats
path: root/crypto/mem.c
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>1999-12-18 02:34:37 +0000
committerRichard Levitte <levitte@openssl.org>1999-12-18 02:34:37 +0000
commitf3a2a0449613dfe7967bc9df646aff9767d0fd79 (patch)
tree336f8713dc085e4ec5dd5476f637ca379670e984 /crypto/mem.c
parentd8df48a9bccb0f408b11af9a71abbf28a675839b (diff)
- Added more documentation in CHANGES.
- Made CRYPTO_MDEBUG even less used in crypto.h, giving MemCheck_start() and MemCheck_stop() only one possible definition. - Made the values of the debug function pointers in mem.c dependent on the existence of the CRYPTO_MDEBUG macro, and made the rest of the code understand the NULL case. That's it. With this code, the old behvior of the debug functionality is restored, but you can still opt to have it on, even when the library wasn't compiled with a defined CRYPTO_MDEBUG.
Diffstat (limited to 'crypto/mem.c')
-rw-r--r--crypto/mem.c44
1 files changed, 32 insertions, 12 deletions
diff --git a/crypto/mem.c b/crypto/mem.c
index 7d6b5af0b1..f06236e1e2 100644
--- a/crypto/mem.c
+++ b/crypto/mem.c
@@ -68,11 +68,19 @@ static char *(*malloc_func)()= (char *(*)())malloc;
static char *(*realloc_func)()= (char *(*)())realloc;
static void (*free_func)()= (void (*)())free;
+#ifdef CRYPTO_MDEBUG
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;
+#else
+static void (*malloc_debug_func)()= (void (*)())NULL;
+static void (*realloc_debug_func)()= (void (*)())NULL;
+static void (*free_debug_func)()= (void (*)())NULL;
+static void (*set_debug_options_func)()= (void (*)())NULL;
+static int (*get_debug_options_func)()= (int (*)())NULL;
+#endif
void CRYPTO_set_mem_functions(char *(*m)(), char *(*r)(), void (*f)())
{
@@ -128,36 +136,42 @@ void *CRYPTO_malloc_locked(int num, char *file, int line)
{
char *ret = NULL;
- malloc_debug_func(NULL, num, file, line, 0);
+ if (malloc_debug_func != 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);
#endif
- malloc_debug_func(ret, num, file, line, 1);
+ if (malloc_debug_func != NULL)
+ malloc_debug_func(ret, num, file, line, 1);
return ret;
}
void CRYPTO_free_locked(void *str)
{
- free_debug_func(str, 0);
+ if (free_debug_func != NULL)
+ free_debug_func(str, 0);
#ifdef LEVITTE_DEBUG
fprintf(stderr, "LEVITTE_DEBUG: < 0x%p\n", str);
#endif
free_locked_func(str);
- free_debug_func(NULL, 1);
+ if (free_debug_func != NULL)
+ free_debug_func(NULL, 1);
}
void *CRYPTO_malloc(int num, char *file, int line)
{
char *ret = NULL;
- malloc_debug_func(NULL, num, file, line, 0);
+ if (malloc_debug_func != NULL)
+ malloc_debug_func(NULL, num, file, line, 0);
ret = malloc_func(num);
#ifdef LEVITTE_DEBUG
fprintf(stderr, "LEVITTE_DEBUG: > 0x%p (%d)\n", ret, num);
#endif
- malloc_debug_func(ret, num, file, line, 1);
+ if (malloc_debug_func != NULL)
+ malloc_debug_func(ret, num, file, line, 1);
return ret;
}
@@ -166,24 +180,28 @@ void *CRYPTO_realloc(void *str, int num, char *file, int line)
{
char *ret = NULL;
- realloc_debug_func(str, NULL, num, file, line, 0);
+ if (realloc_debug_func != NULL)
+ realloc_debug_func(str, NULL, num, file, line, 0);
ret = realloc_func(str,num);
#ifdef LEVITTE_DEBUG
fprintf(stderr, "LEVITTE_DEBUG: | 0x%p -> 0x%p (%d)\n", str, ret, num);
#endif
- realloc_debug_func(str, ret, num, file, line, 1);
+ if (realloc_debug_func != NULL)
+ realloc_debug_func(str, ret, num, file, line, 1);
return ret;
}
void CRYPTO_free(void *str)
{
- free_debug_func(str, 0);
+ if (free_debug_func != NULL)
+ free_debug_func(str, 0);
#ifdef LEVITTE_DEBUG
fprintf(stderr, "LEVITTE_DEBUG: < 0x%p\n", str);
#endif
free_func(str);
- free_debug_func(NULL, 1);
+ if (free_debug_func != NULL)
+ free_debug_func(NULL, 1);
}
@@ -196,10 +214,12 @@ void *CRYPTO_remalloc(void *a, int num, char *file, int line)
void CRYPTO_set_mem_debug_options(int bits)
{
- set_debug_options_func(bits);
+ if (set_debug_options_func != NULL)
+ set_debug_options_func(bits);
}
int CRYPTO_get_mem_debug_options()
{
- return get_debug_options_func();
+ if (get_debug_options_func != NULL)
+ return get_debug_options_func();
}