[openssl-commits] [openssl] master update

Matt Caswell matt at openssl.org
Tue Feb 9 23:32:15 UTC 2016


The branch master has been updated
       via  b7326ea7106955a7a5b8190fb19c982b49b7c821 (commit)
       via  38a6d7f89a6d060b7d463cbdd15eada434bb2d69 (commit)
      from  7839b735d884cfa10d18c39c79fea48b97fcb634 (commit)


- Log -----------------------------------------------------------------
commit b7326ea7106955a7a5b8190fb19c982b49b7c821
Author: Matt Caswell <matt at openssl.org>
Date:   Tue Feb 9 23:09:44 2016 +0000

    NULL the thread_local_inits_st pointer after use
    
    After the final use of the thread_local_inits_st we should ensure it is
    set to NULL, just in case OPENSSL_INIT_thread_stop gets called again and
    it tries to use garbage.
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>

commit 38a6d7f89a6d060b7d463cbdd15eada434bb2d69
Author: Matt Caswell <matt at openssl.org>
Date:   Tue Feb 9 22:09:56 2016 +0000

    Stop library before checking for mem leaks
    
    With the new init framework resources aren't released until the process
    exits. This means checking for mem leaks before that point finds a lot of
    things! We should explicitly close down the library if we're checking for
    mem leaks.
    
    Reviewed-by: Rich Salz <rsalz at openssl.org>

-----------------------------------------------------------------------

Summary of changes:
 crypto/include/internal/cryptlib_int.h |  2 +-
 crypto/init.c                          | 24 +++++++++++++++++++-----
 crypto/mem_dbg.c                       |  3 +++
 3 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/crypto/include/internal/cryptlib_int.h b/crypto/include/internal/cryptlib_int.h
index 36c0a10..0e45762 100644
--- a/crypto/include/internal/cryptlib_int.h
+++ b/crypto/include/internal/cryptlib_int.h
@@ -63,7 +63,7 @@ struct thread_local_inits_st {
     int async;
     int err_state;
 };
-void *ossl_init_get_thread_local(int alloc);
+
 int ossl_init_thread_start(uint64_t opts);
 /*
  * OPENSSL_INIT flags. The primary list of these is in crypto.h. Flags below
diff --git a/crypto/init.c b/crypto/init.c
index b9cc6a1..f23227e 100644
--- a/crypto/init.c
+++ b/crypto/init.c
@@ -95,11 +95,19 @@ static void ossl_init_thread_stop_cleanup(void)
 }
 
 static struct thread_local_inits_st *local = NULL;
-void *ossl_init_get_thread_local(int alloc)
+static struct thread_local_inits_st *ossl_init_get_thread_local(int alloc)
 {
+    static struct thread_local_inits_st *tmp;
+
+    tmp = local;
+
     if (local == NULL && alloc)
-        local = OPENSSL_zalloc(sizeof(*local));
-    return local;
+        tmp = local = OPENSSL_zalloc(sizeof(*local));
+
+    if (!alloc)
+        local = NULL;
+
+    return tmp;
 }
 
 #elif defined(OPENSSL_SYS_WINDOWS)
@@ -182,7 +190,7 @@ static void ossl_init_thread_stop_cleanup(void)
     }
 }
 
-void *ossl_init_get_thread_local(int alloc)
+static struct thread_local_inits_st *ossl_init_get_thread_local(int alloc)
 {
     struct thread_local_inits_st *local = TlsGetValue(threadstopkey);
 
@@ -190,6 +198,9 @@ void *ossl_init_get_thread_local(int alloc)
         local = OPENSSL_zalloc(sizeof *local);
         TlsSetValue(threadstopkey, local);
     }
+    if (!alloc) {
+        TlsSetValue(threadstopkey, NULL);
+    }
 
     return local;
 }
@@ -227,7 +238,7 @@ static void ossl_init_thread_stop_cleanup(void)
 {
 }
 
-void *ossl_init_get_thread_local(int alloc)
+static struct thread_local_inits_st *ossl_init_get_thread_local(int alloc)
 {
     struct thread_local_inits_st *local = pthread_getspecific(threadstopkey);
 
@@ -235,6 +246,9 @@ void *ossl_init_get_thread_local(int alloc)
         local = OPENSSL_zalloc(sizeof *local);
         pthread_setspecific(threadstopkey, local);
     }
+    if (!alloc) {
+        pthread_setspecific(threadstopkey, NULL);
+    }
 
     return local;
 }
diff --git a/crypto/mem_dbg.c b/crypto/mem_dbg.c
index 0559044..c3d98ca 100644
--- a/crypto/mem_dbg.c
+++ b/crypto/mem_dbg.c
@@ -639,6 +639,9 @@ int CRYPTO_mem_leaks(BIO *b)
     if (mh == NULL && amih == NULL)
         return 1;
 
+    /* Ensure all resources are released */
+    OPENSSL_INIT_library_stop();
+
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
 
     ml.bio = b;


More information about the openssl-commits mailing list