mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-17 03:03:23 +02:00
* Fix OpenSSLInitialized thread safety (#1739) The init/uninit methods can be called from multiple threads, and thus need synchronization with a mutex. * Renamed mutex variable and use ScopedLock. * Change reference count variable to be an integer, since it’s protected by a mutex and no longer needs to be atomic.
This commit is contained in:

committed by
Aleksandar Fabijanic

parent
b59d74cfb5
commit
40324cdcc0
@@ -84,8 +84,9 @@ protected:
|
||||
static void dynlockDestroy(struct CRYPTO_dynlock_value* lock, const char* file, int line);
|
||||
|
||||
private:
|
||||
static Poco::FastMutex _mutex;
|
||||
static Poco::FastMutex* _mutexes;
|
||||
static Poco::AtomicCounter _rc;
|
||||
static int _rc;
|
||||
static bool _disableSSLInitialization;
|
||||
};
|
||||
|
||||
|
@@ -33,9 +33,9 @@ using Poco::Thread;
|
||||
namespace Poco {
|
||||
namespace Crypto {
|
||||
|
||||
|
||||
Poco::FastMutex OpenSSLInitializer::_mutex;
|
||||
Poco::FastMutex* OpenSSLInitializer::_mutexes(0);
|
||||
Poco::AtomicCounter OpenSSLInitializer::_rc;
|
||||
int OpenSSLInitializer::_rc(0);
|
||||
bool OpenSSLInitializer::_disableSSLInitialization = false;
|
||||
|
||||
OpenSSLInitializer::OpenSSLInitializer()
|
||||
@@ -59,6 +59,7 @@ OpenSSLInitializer::~OpenSSLInitializer()
|
||||
|
||||
void OpenSSLInitializer::initialize()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
if (++_rc == 1)
|
||||
{
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x0907000L
|
||||
@@ -104,6 +105,7 @@ void OpenSSLInitializer::initialize()
|
||||
|
||||
void OpenSSLInitializer::uninitialize()
|
||||
{
|
||||
FastMutex::ScopedLock lock(_mutex);
|
||||
if (--_rc == 0)
|
||||
{
|
||||
if(_mutexes != NULL) {
|
||||
|
Reference in New Issue
Block a user