Move locking and thread ID functions into new files lock.c and thr_id.c,
[openssl.git] / crypto / mem.c
index 6635167228da1c9eb4ee6be3b4a147a1c3bc2af4..347c0d81843c90c2ec0fbc11154f55fc60bbfb9b 100644 (file)
@@ -101,7 +101,7 @@ static void (*free_locked_func)(void *)     = free;
 
 /* may be changed as long as 'allow_customize_debug' is set */
 /* XXX use correct function pointer types */
-#ifdef CRYPTO_MDEBUG
+#if defined(CRYPTO_MDEBUG) && !defined(OPENSSL_FIPSCANISTER)
 /* use default functions from mem_dbg.c */
 static void (*malloc_debug_func)(void *,int,const char *,int,int)
        = CRYPTO_dbg_malloc;
@@ -250,7 +250,6 @@ void CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int),
 void *CRYPTO_malloc_locked(int num, const char *file, int line)
        {
        void *ret = NULL;
-       extern unsigned char cleanse_ctr;
 
        if (num <= 0) return NULL;
 
@@ -267,11 +266,15 @@ void *CRYPTO_malloc_locked(int num, const char *file, int line)
        if (malloc_debug_func != NULL)
                malloc_debug_func(ret, num, file, line, 1);
 
+#ifndef OPENSSL_CPUID_OBJ
         /* Create a dependency on the value of 'cleanse_ctr' so our memory
          * sanitisation function can't be optimised out. NB: We only do
          * this for >2Kb so the overhead doesn't bother us. */
         if(ret && (num > 2048))
+       {       extern unsigned char cleanse_ctr;
                ((unsigned char *)ret)[0] = cleanse_ctr;
+       }
+#endif
 
        return ret;
        }
@@ -291,7 +294,6 @@ void CRYPTO_free_locked(void *str)
 void *CRYPTO_malloc(int num, const char *file, int line)
        {
        void *ret = NULL;
-       extern unsigned char cleanse_ctr;
 
        if (num <= 0) return NULL;
 
@@ -308,12 +310,23 @@ void *CRYPTO_malloc(int num, const char *file, int line)
        if (malloc_debug_func != NULL)
                malloc_debug_func(ret, num, file, line, 1);
 
+#ifndef OPENSSL_CPUID_OBJ
         /* Create a dependency on the value of 'cleanse_ctr' so our memory
          * sanitisation function can't be optimised out. NB: We only do
          * this for >2Kb so the overhead doesn't bother us. */
         if(ret && (num > 2048))
+       {       extern unsigned char cleanse_ctr;
                 ((unsigned char *)ret)[0] = cleanse_ctr;
+       }
+#endif
+
+       return ret;
+       }
+char *CRYPTO_strdup(const char *str, const char *file, int line)
+       {
+       char *ret = CRYPTO_malloc(strlen(str)+1, file, line);
 
+       strcpy(ret, str);
        return ret;
        }