Avoid unconditional store in CRYPTO_malloc.
authorknekritz <knekritz@fb.com>
Tue, 6 Mar 2018 18:21:49 +0000 (13:21 -0500)
committerRich Salz <rsalz@openssl.org>
Tue, 6 Mar 2018 18:21:49 +0000 (13:21 -0500)
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5372)

crypto/mem.c

index b3f7a1fa00d897d57cbf72c08c1a70c8dbc3ad3e..336446789c73eb2d4ee7ff64ac7acd2d25cb6263 100644 (file)
@@ -201,7 +201,14 @@ void *CRYPTO_malloc(size_t num, const char *file, int line)
         return NULL;
 
     FAILTEST();
-    allow_customize = 0;
+    if (allow_customize) {
+        /*
+         * Disallow customization after the first allocation. We only set this
+         * if necessary to avoid a store to the same cache line on every
+         * allocation.
+         */
+        allow_customize = 0;
+    }
 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
     if (call_malloc_debug) {
         CRYPTO_mem_debug_malloc(NULL, num, 0, file, line);
@@ -243,7 +250,6 @@ void *CRYPTO_realloc(void *str, size_t num, const char *file, int line)
         return NULL;
     }
 
-    allow_customize = 0;
 #ifndef OPENSSL_NO_CRYPTO_MDEBUG
     if (call_malloc_debug) {
         void *ret;