Author: markt
Date: Thu Feb  9 11:46:11 2017
New Revision: 1782315

URL: http://svn.apache.org/viewvc?rev=1782315&view=rev
Log:
Correct a regression in the fix for 59797 that triggered a JVM crash on 
shutdown in some Tomcat unit tests when using the APR/native connector.
For Windows, clean the OpenSSL thread map directly on thread exit
For Linux, use APR thread locals to trigger the clean-up

Modified:
    tomcat/native/trunk/native/include/ssl_private.h
    tomcat/native/trunk/native/include/tcn_api.h
    tomcat/native/trunk/native/os/win32/system.c
    tomcat/native/trunk/native/src/jnilib.c
    tomcat/native/trunk/native/src/ssl.c
    tomcat/native/trunk/xdocs/miscellaneous/changelog.xml

Modified: tomcat/native/trunk/native/include/ssl_private.h
URL: 
http://svn.apache.org/viewvc/tomcat/native/trunk/native/include/ssl_private.h?rev=1782315&r1=1782314&r2=1782315&view=diff
==============================================================================
--- tomcat/native/trunk/native/include/ssl_private.h (original)
+++ tomcat/native/trunk/native/include/ssl_private.h Thu Feb  9 11:46:11 2017
@@ -362,8 +362,6 @@ int         SSL_callback_next_protos(SSL
 int         SSL_callback_select_next_proto(SSL *, unsigned char **, unsigned 
char *, const unsigned char *, unsigned int,void *);
 int         SSL_callback_alpn_select_proto(SSL *, const unsigned char **, 
unsigned char *, const unsigned char *, unsigned int, void *);
 
-
-void SSL_thread_exit(void);
 #if (OPENSSL_VERSION_NUMBER < 0x10100000L) && ! (defined(WIN32) || 
defined(WIN64))
 unsigned long SSL_ERR_get(void);
 void SSL_ERR_clear(void);

Modified: tomcat/native/trunk/native/include/tcn_api.h
URL: 
http://svn.apache.org/viewvc/tomcat/native/trunk/native/include/tcn_api.h?rev=1782315&r1=1782314&r2=1782315&view=diff
==============================================================================
--- tomcat/native/trunk/native/include/tcn_api.h (original)
+++ tomcat/native/trunk/native/include/tcn_api.h Thu Feb  9 11:46:11 2017
@@ -40,10 +40,6 @@
  */
 apr_pool_t *tcn_get_global_pool(void);
 
-/* Return global apr pool, optionally creating it if necessary
- */
-apr_pool_t *tcn_get_global_pool_int(int);
-
 /* Return global String class
  */
 jclass tcn_get_string_class(void);

Modified: tomcat/native/trunk/native/os/win32/system.c
URL: 
http://svn.apache.org/viewvc/tomcat/native/trunk/native/os/win32/system.c?rev=1782315&r1=1782314&r2=1782315&view=diff
==============================================================================
--- tomcat/native/trunk/native/os/win32/system.c (original)
+++ tomcat/native/trunk/native/os/win32/system.c Thu Feb  9 11:46:11 2017
@@ -102,9 +102,7 @@ DllMain(
          */
         case DLL_THREAD_DETACH:
 #ifdef HAVE_OPENSSL
-            if (tcn_get_global_pool_int(0)) {
-                SSL_thread_exit();
-            }
+            ERR_remove_thread_state(NULL);
 #endif
             break;
 

Modified: tomcat/native/trunk/native/src/jnilib.c
URL: 
http://svn.apache.org/viewvc/tomcat/native/trunk/native/src/jnilib.c?rev=1782315&r1=1782314&r2=1782315&view=diff
==============================================================================
--- tomcat/native/trunk/native/src/jnilib.c (original)
+++ tomcat/native/trunk/native/src/jnilib.c Thu Feb  9 11:46:11 2017
@@ -454,12 +454,7 @@ TCN_IMPLEMENT_CALL(jint, Library, size)(
 
 apr_pool_t *tcn_get_global_pool()
 {
-    return tcn_get_global_pool_int(1);
-}
-
-apr_pool_t *tcn_get_global_pool_int(int create)
-{
-    if (!tcn_global_pool && create) {
+    if (!tcn_global_pool) {
         if (apr_pool_create(&tcn_global_pool, NULL) != APR_SUCCESS) {
             return NULL;
         }

Modified: tomcat/native/trunk/native/src/ssl.c
URL: 
http://svn.apache.org/viewvc/tomcat/native/trunk/native/src/ssl.c?rev=1782315&r1=1782314&r2=1782315&view=diff
==============================================================================
--- tomcat/native/trunk/native/src/ssl.c (original)
+++ tomcat/native/trunk/native/src/ssl.c Thu Feb  9 11:46:11 2017
@@ -50,8 +50,10 @@ struct CRYPTO_dynlock_value {
     apr_thread_mutex_t *mutex;
 };
 
+#if ! (defined(WIN32) || defined(WIN64))
 apr_threadkey_t *thread_exit_key;
 #endif
+#endif
 
 /*
  * supported_ssl_opts is a bitmask that contains all supported SSL_OP_*
@@ -437,15 +439,13 @@ static unsigned long ssl_thread_id(void)
 #endif
 }
 
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+#if ! (defined(WIN32) || defined(WIN64))
 void SSL_thread_exit(void) {
-#if (OPENSSL_VERSION_NUMBER < 0x10100000L)
     ERR_remove_thread_state(NULL);
     apr_threadkey_private_set(NULL, thread_exit_key);
-#endif
 }
 
-#if OPENSSL_VERSION_NUMBER < 0x10100000L
-#if ! (defined(WIN32) || defined(WIN64))
 unsigned long SSL_ERR_get() {
     apr_threadkey_private_set(thread_exit_key, thread_exit_key);
     return ERR_get_error();
@@ -455,12 +455,12 @@ void SSL_ERR_clear() {
     apr_threadkey_private_set(thread_exit_key, thread_exit_key);
     ERR_clear_error();
 }
-#endif
 
 static void _ssl_thread_exit(void *data) {
     UNREFERENCED(data);
     SSL_thread_exit();
 }
+#endif
 
 static void ssl_set_thread_id(CRYPTO_THREADID *id)
 {
@@ -758,6 +758,7 @@ TCN_IMPLEMENT_CALL(jint, SSL, initialize
     OPENSSL_load_builtin_modules();
 
 #if OPENSSL_VERSION_NUMBER < 0x10100000L
+#if ! (defined(WIN32) || defined(WIN64))
     err = apr_threadkey_private_create(&thread_exit_key, _ssl_thread_exit,
                                        tcn_global_pool);
     if (err != APR_SUCCESS) {
@@ -765,7 +766,7 @@ TCN_IMPLEMENT_CALL(jint, SSL, initialize
         tcn_ThrowAPRException(e, err);
         return (jint)err;
     }
-
+#endif
     /* Initialize thread support */
     ssl_thread_setup(tcn_global_pool);
 #endif

Modified: tomcat/native/trunk/xdocs/miscellaneous/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/native/trunk/xdocs/miscellaneous/changelog.xml?rev=1782315&r1=1782314&r2=1782315&view=diff
==============================================================================
--- tomcat/native/trunk/xdocs/miscellaneous/changelog.xml (original)
+++ tomcat/native/trunk/xdocs/miscellaneous/changelog.xml Thu Feb  9 11:46:11 
2017
@@ -35,6 +35,13 @@
   </p>
 </section>
 <section name="Changes in 1.2.12">
+  <changelog>
+    <fix>
+      Correct a regression in the fix for <bug>59797</bug> that triggered a JVM
+      crash on shutdown in some Tomcat unit tests when using the APR/native
+      connector. (markt)
+    </fix>
+  </changelog>
 </section>
 <section name="Changes in 1.2.11">
   <changelog>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to