diff options
author | Matt Caswell <matt@openssl.org> | 2016-03-11 22:53:18 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2016-04-14 14:19:04 +0200 |
commit | ff2344052bfa0132260ee3154962a2552f3d95f5 (patch) | |
tree | 4ab28127a480a46064e730088339e4fe6dbd7cfc | |
parent | Fix the spelling of "implement". (diff) | |
download | openssl-ff2344052bfa0132260ee3154962a2552f3d95f5.tar.xz openssl-ff2344052bfa0132260ee3154962a2552f3d95f5.zip |
Ensure all locks are properly cleaned up
Some locks were not being properly cleaned up during close down.
Reviewed-by: Richard Levitte <levitte@openssl.org>
-rw-r--r-- | crypto/bio/b_addr.c | 3 | ||||
-rw-r--r-- | crypto/bio/bio_lcl.h | 4 | ||||
-rw-r--r-- | crypto/bio/bio_lib.c | 10 | ||||
-rw-r--r-- | crypto/err/err.c | 9 | ||||
-rw-r--r-- | crypto/ex_data.c | 10 | ||||
-rw-r--r-- | crypto/include/internal/cryptlib_int.h | 2 | ||||
-rw-r--r-- | crypto/init.c | 10 | ||||
-rw-r--r-- | include/internal/bio.h | 2 | ||||
-rw-r--r-- | include/internal/err.h | 1 |
9 files changed, 41 insertions, 10 deletions
diff --git a/crypto/bio/b_addr.c b/crypto/bio/b_addr.c index ed4c1397d9..eed40bf8b5 100644 --- a/crypto/bio/b_addr.c +++ b/crypto/bio/b_addr.c @@ -62,7 +62,7 @@ #include <openssl/buffer.h> #include <ctype.h> -static CRYPTO_RWLOCK *bio_lookup_lock; +CRYPTO_RWLOCK *bio_lookup_lock; static CRYPTO_ONCE bio_lookup_init = CRYPTO_ONCE_STATIC_INIT; /* @@ -891,4 +891,5 @@ int BIO_lookup(const char *host, const char *service, return ret; } + #endif /* OPENSSL_NO_SOCK */ diff --git a/crypto/bio/bio_lcl.h b/crypto/bio/bio_lcl.h index 7f3b22268a..52c9e79a24 100644 --- a/crypto/bio/bio_lcl.h +++ b/crypto/bio/bio_lcl.h @@ -127,6 +127,8 @@ struct bio_st { typedef unsigned int socklen_t; # endif +extern CRYPTO_RWLOCK *bio_lookup_lock; + int BIO_ADDR_make(BIO_ADDR *ap, const struct sockaddr *sa); const struct sockaddr *BIO_ADDR_sockaddr(const BIO_ADDR *ap); struct sockaddr *BIO_ADDR_sockaddr_noconst(BIO_ADDR *ap); @@ -135,6 +137,8 @@ socklen_t BIO_ADDRINFO_sockaddr_size(const BIO_ADDRINFO *bai); const struct sockaddr *BIO_ADDRINFO_sockaddr(const BIO_ADDRINFO *bai); #endif +void bio_sock_cleanup_int(void); + #if BIO_FLAGS_UPLINK==0 /* Shortcut UPLINK calls on most platforms... */ # define UP_stdin stdin diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c index ac98cf2402..025869454f 100644 --- a/crypto/bio/bio_lib.c +++ b/crypto/bio/bio_lib.c @@ -644,3 +644,13 @@ uint64_t BIO_number_written(BIO *bio) return bio->num_write; return 0; } + + +void bio_cleanup(void) +{ +#ifndef OPENSSL_NO_SOCK + bio_sock_cleanup_int(); + CRYPTO_THREAD_lock_free(bio_lookup_lock); + bio_lookup_lock = NULL; +#endif +} diff --git a/crypto/err/err.c b/crypto/err/err.c index 3ee4e861d4..aff3ae5a24 100644 --- a/crypto/err/err.c +++ b/crypto/err/err.c @@ -113,6 +113,7 @@ #include <string.h> #include <internal/cryptlib_int.h> #include <internal/threads.h> +#include <internal/err.h> #include <openssl/lhash.h> #include <openssl/crypto.h> #include <openssl/buffer.h> @@ -389,9 +390,13 @@ static void ERR_STATE_free(ERR_STATE *s) static void do_err_strings_init(void) { - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); err_string_lock = CRYPTO_THREAD_lock_new(); - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); +} + +void err_cleanup(void) +{ + CRYPTO_THREAD_lock_free(err_string_lock); + err_string_lock = NULL; } void ERR_load_ERR_strings(void) diff --git a/crypto/ex_data.c b/crypto/ex_data.c index 44dc46b782..c607f87d65 100644 --- a/crypto/ex_data.c +++ b/crypto/ex_data.c @@ -108,7 +108,7 @@ * */ -#include "internal/cryptlib.h" +#include "internal/cryptlib_int.h" #include "internal/threads.h" #include <openssl/lhash.h> @@ -139,9 +139,13 @@ static CRYPTO_ONCE ex_data_init = CRYPTO_ONCE_STATIC_INIT; static void do_ex_data_init(void) { - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE); ex_data_lock = CRYPTO_THREAD_lock_new(); - CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE); +} + +void ex_data_cleanup(void) +{ + CRYPTO_THREAD_lock_free(ex_data_lock); + ex_data_lock = NULL; } /* diff --git a/crypto/include/internal/cryptlib_int.h b/crypto/include/internal/cryptlib_int.h index ae30842d6d..fd68522936 100644 --- a/crypto/include/internal/cryptlib_int.h +++ b/crypto/include/internal/cryptlib_int.h @@ -65,6 +65,8 @@ struct thread_local_inits_st { }; int ossl_init_thread_start(uint64_t opts); +void ex_data_cleanup(void); + /* * OPENSSL_INIT flags. The primary list of these is in crypto.h. Flags below * are those ommitted from crypto.h because they are "reserverd for internal diff --git a/crypto/init.c b/crypto/init.c index f44e3a84f2..48f74c496c 100644 --- a/crypto/init.c +++ b/crypto/init.c @@ -468,9 +468,13 @@ void OPENSSL_cleanup(void) fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " "bio_sock_cleanup_int()\n"); fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " + "bio_cleanup()\n"); + fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " "evp_cleanup_int()\n"); fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " "obj_cleanup_int()\n"); + fprintf(stderr, "OPENSSL_INIT: OPENSSL_cleanup: " + "err_cleanup()\n"); #endif /* * Note that cleanup order is important: @@ -489,11 +493,11 @@ void OPENSSL_cleanup(void) engine_cleanup_int(); #endif crypto_cleanup_all_ex_data_int(); -#ifndef OPENSSL_NO_SOCK - bio_sock_cleanup_int(); -#endif + bio_cleanup(); evp_cleanup_int(); obj_cleanup_int(); + err_cleanup(); + base_inited = 0; } diff --git a/include/internal/bio.h b/include/internal/bio.h index e62580b003..ec9dff69d2 100644 --- a/include/internal/bio.h +++ b/include/internal/bio.h @@ -67,4 +67,4 @@ struct bio_method_st { long (*callback_ctrl) (BIO *, int, bio_info_cb *); }; -void bio_sock_cleanup_int(void); +void bio_cleanup(void); diff --git a/include/internal/err.h b/include/internal/err.h index de2180b34b..415f578f09 100644 --- a/include/internal/err.h +++ b/include/internal/err.h @@ -59,5 +59,6 @@ # define INTERNAL_ERR_H void err_free_strings_int(void); +void err_cleanup(void); #endif |