Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OpenSSLInitialized thread safety (#1739) #1740

Merged
merged 3 commits into from
Jul 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Crypto/include/Poco/Crypto/OpenSSLInitializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ class Crypto_API OpenSSLInitializer
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;
};

Expand Down
6 changes: 4 additions & 2 deletions Crypto/src/OpenSSLInitializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -59,6 +59,7 @@ OpenSSLInitializer::~OpenSSLInitializer()

void OpenSSLInitializer::initialize()
{
FastMutex::ScopedLock lock(_mutex);
if (++_rc == 1)
{
#if OPENSSL_VERSION_NUMBER >= 0x0907000L
Expand Down Expand Up @@ -104,6 +105,7 @@ void OpenSSLInitializer::initialize()

void OpenSSLInitializer::uninitialize()
{
FastMutex::ScopedLock lock(_mutex);
if (--_rc == 0)
{
if(_mutexes != NULL) {
Expand Down