It's easy enough to set up the OpenSSL callbacks to make it thread safe so why not just do it and see if the problem goes away.
Whilst you've reasoned that there's no need to do so the fact that there's a potential problem shouldn't blind you to a potentially easy fix to the issue even if "there's no way it should be that"...
Here's the code that I use for this,
struct CRYPTO_dynlock_value
{
CRYPTO_dynlock_value()
{
::InitializeCriticalSection(&crit);
}
~CRYPTO_dynlock_value()
{
::DeleteCriticalSection(&crit);
}
CRITICAL_SECTION crit;
};
static CRITICAL_SECTION *InitStaticCrit()
{
CRITICAL_SECTION *pCrit = new CRITICAL_SECTION();
::InitializeCriticalSection(pCrit);
return pCrit;
}
static CRITICAL_SECTION *s_pCriticalSection = InitStaticCrit();
static CRITICAL_SECTION *s_pLocks = 0;
static struct CRYPTO_dynlock_value *dyn_create_function(
const char *file,
int line)
{
(void)file;
(void)line;
CRYPTO_dynlock_value *pValue = new CRYPTO_dynlock_value();
return pValue;
}
static void dyn_lock_function(
int mode,
struct CRYPTO_dynlock_value *pLock,
const char *file,
int line)
{
(void)file;
(void)line;
if (mode & CRYPTO_LOCK)
{
::EnterCriticalSection(&pLock->crit);
}
else
{
::LeaveCriticalSection(&pLock->crit);
}
}
static void dyn_destroy_function(
struct CRYPTO_dynlock_value *pLock,
const char *file,
int line)
{
(void)file;
(void)line;
delete pLock;
}
static bool ThreadingSetup(
const DWORD spinCount)
{
::EnterCriticalSection(&s_criticalSection);
bool ok = false;
if (!s_pLocks)
{
s_pLocks = (CRITICAL_SECTION *)malloc(CRYPTO_num_locks() * sizeof(CRITICAL_SECTION));
for (int i = 0; i < CRYPTO_num_locks(); i++)
{
if (spinCount != 0)
{
#if(_WIN32_WINNT >= 0x0403)
(void)::InitializeCriticalSectionAndSpinCount(&s_pLocks[i], spinCount);
#else
#pragma warning(suppress: 6011) // Dereferencing null pointer. No, we're not.
::InitializeCriticalSection(&s_pLocks[i]);
OutputDebugString(_T("CUsesOpenSSL::ThreadingSetup() - spin count specified but _WIN32_WINNT < 0x0403, spin count not used\n"));
#endif
}
else
{
#pragma warning(suppress: 6011) // Dereferencing null pointer. No, we're not.
::InitializeCriticalSection(&s_pLocks[i]);
}
}
CRYPTO_set_locking_callback(LockingCallback);
//CRYPTO_set_id_callback(id_function);
// dynamic locks callbacks
CRYPTO_set_dynlock_create_callback(dyn_create_function);
CRYPTO_set_dynlock_lock_callback(dyn_lock_function);
CRYPTO_set_dynlock_destroy_callback(dyn_destroy_function);
ok = true;
}
::LeaveCriticalSection(&s_criticalSection);
return ok;
}
static void ThreadingCleanup()
{
if (s_pLocks)
{
CRYPTO_set_locking_callback(0);
CRYPTO_set_dynlock_create_callback(0);
CRYPTO_set_dynlock_lock_callback(0);
CRYPTO_set_dynlock_destroy_callback(0);
for (int i = 0; i < CRYPTO_num_locks(); i++)
{
::DeleteCriticalSection(&s_pLocks[i]);
}
free(s_pLocks);
s_pLocks = 0;
}
}
static void LockingCallback(
int mode,
int type,
const char * /*file*/,
int /*line*/)
{
if (mode & CRYPTO_LOCK)
{
::EnterCriticalSection(&s_pLocks[type]);
}
else
{
::LeaveCriticalSection(&s_pLocks[type]);
}
}