- Added more documentation in CHANGES.
authorRichard Levitte <levitte@openssl.org>
Sat, 18 Dec 1999 02:34:37 +0000 (02:34 +0000)
committerRichard Levitte <levitte@openssl.org>
Sat, 18 Dec 1999 02:34:37 +0000 (02:34 +0000)
 - 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.

CHANGES
crypto/crypto.h
crypto/mem.c

diff --git a/CHANGES b/CHANGES
index c71f74af99daade6a0c9938f5085a8144b922bd7..14208b984d6e002003c80b344a2a5cc1d81632f9 100644 (file)
--- a/CHANGES
+++ b/CHANGES
      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
index 863b4e922426ae0023f6a63bdccdb24c17999a55..19e8d10cbf18a898861a8baf84d87a64b72ea99b 100644 (file)
@@ -217,8 +217,8 @@ typedef struct crypto_ex_data_func_st
                (void (*)())CRYPTO_dbg_realloc,\
                (void (*)())CRYPTO_dbg_free,\
                (void (*)())CRYPTO_dbg_set_options,\
-               (void (*)())CRYPTO_dbg_get_options);\
-       } while(0);
+               (int (*)())CRYPTO_dbg_get_options);\
+       } while(0)
 
 #if defined CRYPTO_MDEBUG_ALL || defined CRYPTO_MDEBUG_TIME || defined CRYPTO_MDEBUG_THREAD
 # ifndef CRYPTO_MDEBUG /* avoid duplicate #define */
@@ -226,13 +226,8 @@ typedef struct crypto_ex_data_func_st
 # endif
 #endif
 
-#ifdef CRYPTO_MDEBUG
 #define MemCheck_start() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON)
 #define MemCheck_stop()        CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_OFF)
-#else
-#define MemCheck_start()
-#define MemCheck_stop()
-#endif
 #define MemCheck_on()  CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE)
 #define MemCheck_off() CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE)
 #define is_MemCheck_on() CRYPTO_mem_check_on()
index 7d6b5af0b1b11402a60c1c2729431c4e37e443b8..f06236e1e219a3ff789125d6ce49c6455d2c2fea 100644 (file)
@@ -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();
        }