Ensure all locks are properly cleaned up
authorMatt Caswell <matt@openssl.org>
Fri, 11 Mar 2016 21:53:18 +0000 (21:53 +0000)
committerMatt Caswell <matt@openssl.org>
Thu, 14 Apr 2016 12:19:04 +0000 (13:19 +0100)
Some locks were not being properly cleaned up during close down.

Reviewed-by: Richard Levitte <levitte@openssl.org>
crypto/bio/b_addr.c
crypto/bio/bio_lcl.h
crypto/bio/bio_lib.c
crypto/err/err.c
crypto/ex_data.c
crypto/include/internal/cryptlib_int.h
crypto/init.c
include/internal/bio.h
include/internal/err.h

index ed4c1397d97bc9ba3839a654081adf9eb7ac6d48..eed40bf8b5f427225d43c59f7d2fae7c2e8b1a04 100644 (file)
@@ -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 */
index 7f3b22268a1e530c6f610bfc6f8e0eacc7f3381c..52c9e79a24c688b5070c6c0b149ccd0e9fb31287 100644 (file)
@@ -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
index ac98cf240220ceb2268375977d76ec0c2ddf1847..025869454fa511a1f971692cfab4344652402339 100644 (file)
@@ -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
+}
index 3ee4e861d4b227c919f35a966f43e808c32cacb1..aff3ae5a24e75656d6e96c5fb12c94011bc35232 100644 (file)
 #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)
index 44dc46b7823862184617402af53ce16ec0a919ca..c607f87d654bc5879a38fb087dbf820201575599 100644 (file)
  *
  */
 
-#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;
 }
 
 /*
index ae30842d6de132ff2041b8da66fbd8b46279d204..fd685229365ef000cbaf43668a2161423928340d 100644 (file)
@@ -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
index f44e3a84f2e53dd55ae6c638e7df5f51e1f9ca2a..48f74c496c0c73b9490fe2f8aca140cd122824e3 100644 (file)
@@ -467,10 +467,14 @@ void OPENSSL_cleanup(void)
                     "crypto_cleanup_all_ex_data_int()\n");
     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;
 }
 
index e62580b003a6e5e919f851c0c0ece3aeef96b644..ec9dff69d231d1bbc72ca0dec8f1f05a6dcb3c17 100644 (file)
@@ -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);
index de2180b34bfcb71f977641b4725cd8b1f7b2adb2..415f578f096e760d9153bf778644e1e00e0b0cc2 100644 (file)
@@ -59,5 +59,6 @@
 # define INTERNAL_ERR_H
 
 void err_free_strings_int(void);
+void err_cleanup(void);
 
 #endif