Description: Ensure the ABI stays compatible
 Upstream accidentically introduced an ABI incompatible change in
 4.1.2.  This patch reverts this change.
 .
 Upstream rejected this since the damage had already been done and
 they didn't want to break the ABI twice.
Forwarded: http://www.omniorb-support.com/pipermail/omniorb-list/2008-April/029347.html
Author: Thomas Girard <thomas.g.girard@free.fr>
Last-Update: 2010-08-08

--- a/include/omniORB4/sslContext.h
+++ b/include/omniORB4/sslContext.h
@@ -160,7 +160,6 @@
   const char* 	    pd_password;
   SSL_CTX*    	    pd_ctx;
   omni_tracedmutex* pd_locks;
-  CORBA::Boolean    pd_ssl_owner;
 };
 
 #undef _core_attr
--- a/src/lib/omniORB/orbcore/ssl/sslContext.cc
+++ b/src/lib/omniORB/orbcore/ssl/sslContext.cc
@@ -122,19 +122,42 @@
 
 sslContext* sslContext::singleton = 0;
 
+static sslContext* ssl_owner = 0;
+
+static bool become_ssl_owner(sslContext* context) {
+  bool become_owner = false;
+
+  if (ssl_owner == 0 && CRYPTO_get_locking_callback() == 0) {
+    ssl_owner = context;
+    become_owner = true;
+  }
+
+  return become_owner;
+}
+
+static bool was_ssl_owner(sslContext* context) {
+  bool was_owner = false;
+
+  if (ssl_owner != 0 && ssl_owner == context) {
+    was_owner = true;
+    ssl_owner = 0;
+  }
+
+  return was_owner;
+}
 
 /////////////////////////////////////////////////////////////////////////
 sslContext::sslContext(const char* cafile,
 		       const char* keyfile,
 		       const char* password) :
   pd_cafile(cafile), pd_keyfile(keyfile), pd_password(password), pd_ctx(0),
-  pd_locks(0), pd_ssl_owner(0) {}
+  pd_locks(0) {}
 
 
 /////////////////////////////////////////////////////////////////////////
 sslContext::sslContext() :
   pd_cafile(0), pd_keyfile(0), pd_password(0), pd_ctx(0),
-  pd_locks(0), pd_ssl_owner(0) {
+  pd_locks(0) {
 }
 
 /////////////////////////////////////////////////////////////////////////
@@ -144,7 +167,7 @@
   if (pd_ctx) return;
 
   // Assume we own the ssl if no locking callback yet.
-  pd_ssl_owner = CRYPTO_get_locking_callback() == 0;
+  bool pd_ssl_owner = become_ssl_owner(this);
 
   if (pd_ssl_owner) {
     SSL_library_init();
@@ -189,7 +212,7 @@
   if (pd_ctx) {
     SSL_CTX_free(pd_ctx);
   }
-  if (pd_ssl_owner)
+  if (was_ssl_owner(this))
     thread_cleanup();
 }
 
