Fix mem leaks during auto-deinit
authorMatt Caswell <matt@openssl.org>
Mon, 5 Sep 2016 13:12:58 +0000 (14:12 +0100)
committerMatt Caswell <matt@openssl.org>
Thu, 8 Sep 2016 11:40:19 +0000 (12:40 +0100)
Certain functions are automatically called during auto-deinit in order
to deallocate resources. However, if we have never entered a function which
marks lib crypto as inited then they never get called. This can happen if
the user only ever makes use of a small sub-set of functions that don't hit
the auto-init code.

This commit ensures all such resources deallocated by these functions also
init libcrypto when they are initially allocated.

Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Ben Laurie <ben@openssl.org>
crypto/bio/b_addr.c
crypto/engine/eng_lib.c
crypto/err/err.c
crypto/ex_data.c
crypto/rand/md_rand.c

index f924e1029f80331d5b32124b85dcaeb4e6c9e059..29f92cf7c72ea592bdd0d6546f4a7b4bfc207395 100644 (file)
@@ -604,6 +604,7 @@ static int addrinfo_wrap(int family, int socktype,
 
 DEFINE_RUN_ONCE_STATIC(do_bio_lookup_init)
 {
+    OPENSSL_init_crypto(0, NULL);
     bio_lookup_lock = CRYPTO_THREAD_lock_new();
     return bio_lookup_lock != NULL;
 }
index 67d755a2aa988d6471236012987cdefe54d74182..28de21d73de6d6ecb0a168a8a34ee2d62a1a00e4 100644 (file)
@@ -18,6 +18,7 @@ CRYPTO_ONCE engine_lock_init = CRYPTO_ONCE_STATIC_INIT;
 
 DEFINE_RUN_ONCE(do_engine_lock_init)
 {
+    OPENSSL_init_crypto(0, NULL);
     global_engine_lock = CRYPTO_THREAD_lock_new();
     return global_engine_lock != NULL;
 }
index 584bb9e10d0002add99aa0c2abe59c8d1c7cb621..c3f7212a78c5e9d64a2f8e7dae1e6c20b3e12f01 100644 (file)
@@ -251,6 +251,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_lock_new();
     return err_string_lock != NULL;
 }
index 986ef70bc440c4e49a17e1c4fb1cc14187e20554..bb1af0b3b1f62fe5040dc8a16c4bea0192a11b0a 100644 (file)
@@ -38,6 +38,7 @@ static CRYPTO_ONCE ex_data_init = CRYPTO_ONCE_STATIC_INIT;
 
 DEFINE_RUN_ONCE_STATIC(do_ex_data_init)
 {
+    OPENSSL_init_crypto(0, NULL);
     ex_data_lock = CRYPTO_THREAD_lock_new();
     return ex_data_lock != NULL;
 }
index 7924478e9e8973654938941c4fa44775a24adf56..85ce4e6f982ed299cf1695a9f2b6a8cd4cce4eb2 100644 (file)
@@ -89,6 +89,7 @@ static RAND_METHOD rand_meth = {
 
 DEFINE_RUN_ONCE_STATIC(do_rand_lock_init)
 {
+    OPENSSL_init_crypto(0, NULL);
     rand_lock = CRYPTO_THREAD_lock_new();
     rand_tmp_lock = CRYPTO_THREAD_lock_new();
     return rand_lock != NULL && rand_tmp_lock != NULL;