X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=crypto%2Finit.c;h=26021d9494f20b95fdf26352d18a454dfc4d025a;hp=1bfde6973ceb41c114296ea50f2188f03fc336dd;hb=1ffa8a9685e22a5a0ff1b1322df4d1720b05ce4c;hpb=bf24111bb2cf37b609fecdbe81660ecfd460e998 diff --git a/crypto/init.c b/crypto/init.c index 1bfde6973c..26021d9494 100644 --- a/crypto/init.c +++ b/crypto/init.c @@ -55,17 +55,6 @@ * */ -#include - -#if defined(OPENSSL_SYS_WINDOWS) && !defined(_WIN32_WINNT) -/* - * We default to requiring Windows Vista, Windows Server 2008 or later. We can - * support lower versions if _WIN32_WINNT is explicity defined to something - * less - */ -# define _WIN32_WINNT 0x0600 -#endif - #include #include #include @@ -106,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) @@ -171,7 +168,7 @@ static void ossl_init_once_run(OPENSSL_INIT_ONCE *once, void (*init)(void)) } # endif -DWORD threadstopkey = TLS_OUT_OF_INDEXES; +static DWORD threadstopkey = TLS_OUT_OF_INDEXES; static int ossl_init_setup_thread_stop(void) { @@ -193,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); @@ -201,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; } @@ -208,7 +208,7 @@ void *ossl_init_get_thread_local(int alloc) #else /* pthreads */ # include -pthread_key_t threadstopkey; +static pthread_key_t threadstopkey; typedef pthread_once_t OPENSSL_INIT_ONCE; # define OPENSSL_INIT_ONCE_STATIC_INIT PTHREAD_ONCE_INIT @@ -238,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); @@ -246,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; }