summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
authorMark Spruiell <mes@zeroc.com>2005-01-20 14:20:15 +0000
committerMark Spruiell <mes@zeroc.com>2005-01-20 14:20:15 +0000
commitf2cdc3492f9a4084a9bdaaecacf7b50c7444f535 (patch)
tree8b6909edecdb45f8a8824b9e0f3c0cb70e6cfff6 /cpp/src
parentFixed Win32 build (diff)
downloadice-f2cdc3492f9a4084a9bdaaecacf7b50c7444f535.tar.bz2
ice-f2cdc3492f9a4084a9bdaaecacf7b50c7444f535.tar.xz
ice-f2cdc3492f9a4084a9bdaaecacf7b50c7444f535.zip
fix for cleanup bug in IceSSL
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IceSSL/OpenSSLPluginI.cpp64
1 files changed, 41 insertions, 23 deletions
diff --git a/cpp/src/IceSSL/OpenSSLPluginI.cpp b/cpp/src/IceSSL/OpenSSLPluginI.cpp
index dcb72b028d8..241742ff67c 100644
--- a/cpp/src/IceSSL/OpenSSLPluginI.cpp
+++ b/cpp/src/IceSSL/OpenSSLPluginI.cpp
@@ -54,6 +54,9 @@ using namespace IceSSL;
void IceInternal::incRef(OpenSSLPluginI* p) { p->__incRef(); }
void IceInternal::decRef(OpenSSLPluginI* p) { p->__decRef(); }
+static IceUtil::StaticMutex staticMutex = ICE_STATIC_MUTEX_INITIALIZER;
+static int instanceCount = 0;
+
//
// Plugin factory function
//
@@ -186,22 +189,32 @@ IceSSL::OpenSSLPluginI::OpenSSLPluginI(const IceInternal::ProtocolPluginFacadePt
_clientContext(new TraceLevels(protocolPluginFacade), protocolPluginFacade->getCommunicator()),
_randSeeded(0)
{
- if(_memDebug != 0)
- {
- CRYPTO_malloc_debug_init();
- CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
- CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
- }
- else
+ //
+ // It is possible for multiple instances of OpenSSLPluginI to be created
+ // (one for each communicator). We use a mutex-protected counter to know
+ // when to initialize and clean up OpenSSL.
+ //
+ IceUtil::StaticMutex::Lock sync(staticMutex);
+ if(instanceCount == 0)
{
- CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
- }
+ if(_memDebug != 0)
+ {
+ CRYPTO_malloc_debug_init();
+ CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
+ CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
+ }
+ else
+ {
+ CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
+ }
- SSL_library_init();
+ SSL_library_init();
- SSL_load_error_strings();
+ SSL_load_error_strings();
- OpenSSL_add_ssl_algorithms();
+ OpenSSL_add_ssl_algorithms();
+ }
+ ++instanceCount;
}
IceSSL::OpenSSLPluginI::~OpenSSLPluginI()
@@ -209,23 +222,28 @@ IceSSL::OpenSSLPluginI::~OpenSSLPluginI()
_serverContext.cleanUp();
_clientContext.cleanUp();
+ unregisterThreads();
+
+ IceUtil::StaticMutex::Lock sync(staticMutex);
+ if(--instanceCount == 0)
+ {
#if OPENSSL_VERSION_NUMBER >= 0x0090700fL
- ENGINE_cleanup();
- CRYPTO_cleanup_all_ex_data();
+ ENGINE_cleanup();
+ CRYPTO_cleanup_all_ex_data();
#endif
- // TODO: Introduces a 72byte memory leak, if we kidnap the code from OpenSSL 0.9.7a for
- // ENGINE_cleanup(), we can fix that.
+ // TODO: Introduces a 72byte memory leak, if we kidnap the code from OpenSSL 0.9.7a for
+ // ENGINE_cleanup(), we can fix that.
- ERR_free_strings();
- unregisterThreads();
- ERR_remove_state(0);
+ ERR_free_strings();
+ ERR_remove_state(0);
- EVP_cleanup();
+ EVP_cleanup();
- if(_memDebug != 0)
- {
- CRYPTO_mem_leaks_fp(stderr);
+ if(_memDebug != 0)
+ {
+ CRYPTO_mem_leaks_fp(stderr);
+ }
}
}