memory leaks, but this gives people a chance to debug other memory
problems.
- This change means that a call `CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON)'
- is no longer dependent on if the macro CRYPTO_MDEBUG or friends were
- used when the OpenSSL libcrypto was built. This is under debate and
- may change back, but with another option to still get debugging even
- if the library wasn't compiled that way.
+ With these changes, a new set of functions and macros have appeared:
+
+ CRYPTO_set_mem_debug_functions() [F]
+ CRYPTO_get_mem_debug_functions() [F]
+ CRYPTO_dbg_set_options() [F]
+ CRYPTO_dbg_get_options() [F]
+ CRYPTO_melloc_debug_init() [M]
+
+ The memory debug functions are NULL by default, unless the library
+ is compiled with CRYPTO_MDEBUG or friends is defined. If someone
+ wants to debug memory anyway, CRYPTO_malloc_debug_init() or
+ CRYPTO_set_mem_debug_functions() must be used.
+
+ Also, things like CRYPTO_set_mem_functions will always give the
+ expected result (the new set of functions is used for allocation
+ and deallocation) at all times, regardless of platform and compiler
+ options.
+
+ To finish it up, some functions that were never use in any other
+ way than through macros have a new API and new semantic:
+
+ CRYPTO_dbg_malloc()
+ CRYPTO_dbg_realloc()
+ CRYPTO_dbg_free()
+
+ All macros of value have retained their old syntax.
[Richard Levitte]
*) Some S/MIME fixes. The OID for SMIMECapabilities was wrong, the
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)())
{
{
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;
}
{
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);
}
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();
}