From: knekritz Date: Tue, 6 Mar 2018 18:21:49 +0000 (-0500) Subject: Avoid unconditional store in CRYPTO_malloc. X-Git-Tag: OpenSSL_1_1_0h~50 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=4044ebfe2481c240cb37cfcb0e6176fe79394db4;p=oweals%2Fopenssl.git Avoid unconditional store in CRYPTO_malloc. Reviewed-by: Richard Levitte Reviewed-by: Rich Salz (Merged from https://github.com/openssl/openssl/pull/5372) (cherry picked from commit 41aede863b76202347c2d5e2c2666428084f9203) --- diff --git a/crypto/mem.c b/crypto/mem.c index bc35132fc7..7ec7a80cd0 100644 --- a/crypto/mem.c +++ b/crypto/mem.c @@ -78,7 +78,14 @@ void *CRYPTO_malloc(size_t num, const char *file, int line) if (num == 0) return NULL; - 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); @@ -117,7 +124,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;