X-Git-Url: https://git.openssl.org/gitweb/?a=blobdiff_plain;f=crypto%2Ferr%2Ferr.c;h=d69fbf870a97ccfc86041f43d513eb50761f7241;hb=3ce1c27b56fa9856693e5c98331cebaa2a3accfa;hp=bd9e062fd1bee03a8f1a0260945e640855944981;hpb=a0fda2cf2dac8bc0d309261b3aaf4027a188b08c;p=openssl.git diff --git a/crypto/err/err.c b/crypto/err/err.c index bd9e062fd1..d69fbf870a 100644 --- a/crypto/err/err.c +++ b/crypto/err/err.c @@ -1,5 +1,5 @@ /* - * Copyright 1995-2017 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the OpenSSL license (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -266,7 +266,7 @@ static void ERR_STATE_free(ERR_STATE *s) DEFINE_RUN_ONCE_STATIC(do_err_strings_init) { OPENSSL_init_crypto(0, NULL); - err_string_lock = CRYPTO_THREAD_glock_new("err_string"); + err_string_lock = CRYPTO_THREAD_lock_new(); int_error_hash = lh_ERR_STRING_DATA_new(err_string_data_hash, err_string_data_cmp); return err_string_lock != NULL && int_error_hash != NULL; @@ -667,6 +667,14 @@ ERR_STATE *ERR_get_state(void) if (!RUN_ONCE(&err_init, err_do_init)) return NULL; + /* + * If base OPENSSL_init_crypto() hasn't been called yet, be sure to call + * it now to avoid state to be doubly allocated and thereby leak memory. + * Needed on any platform that doesn't define OPENSSL_USE_NODELETE. + */ + if (!OPENSSL_init_crypto(0, NULL)) + return NULL; + state = CRYPTO_THREAD_get_local(&err_thread_local); if (state == NULL) {