mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 21:12:48 +01:00
Merge #10058: No need to use OpenSSL malloc/free
6d5dd60
No need to use OpenSSL malloc/free (Thomas Snider)
Tree-SHA512: 29f790067ffd5a10a8e1a621318a0ba445691f57c804aa3b7c8ca372c8408d8c7fe703c42b48018e400fc32e3feff5ab401d97433910ce2c50e69da0b8a6662e
This commit is contained in:
commit
a2cd0b0eec
17
src/util.cpp
17
src/util.cpp
@ -123,26 +123,24 @@ CTranslationInterface translationInterface;
|
|||||||
std::atomic<uint32_t> logCategories(0);
|
std::atomic<uint32_t> logCategories(0);
|
||||||
|
|
||||||
/** Init OpenSSL library multithreading support */
|
/** Init OpenSSL library multithreading support */
|
||||||
static CCriticalSection** ppmutexOpenSSL;
|
static std::unique_ptr<CCriticalSection[]> ppmutexOpenSSL;
|
||||||
void locking_callback(int mode, int i, const char* file, int line) NO_THREAD_SAFETY_ANALYSIS
|
void locking_callback(int mode, int i, const char* file, int line) NO_THREAD_SAFETY_ANALYSIS
|
||||||
{
|
{
|
||||||
if (mode & CRYPTO_LOCK) {
|
if (mode & CRYPTO_LOCK) {
|
||||||
ENTER_CRITICAL_SECTION(*ppmutexOpenSSL[i]);
|
ENTER_CRITICAL_SECTION(ppmutexOpenSSL[i]);
|
||||||
} else {
|
} else {
|
||||||
LEAVE_CRITICAL_SECTION(*ppmutexOpenSSL[i]);
|
LEAVE_CRITICAL_SECTION(ppmutexOpenSSL[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Init
|
// Singleton for wrapping OpenSSL setup/teardown.
|
||||||
class CInit
|
class CInit
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CInit()
|
CInit()
|
||||||
{
|
{
|
||||||
// Init OpenSSL library multithreading support
|
// Init OpenSSL library multithreading support
|
||||||
ppmutexOpenSSL = (CCriticalSection**)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(CCriticalSection*));
|
ppmutexOpenSSL.reset(new CCriticalSection[CRYPTO_num_locks()]);
|
||||||
for (int i = 0; i < CRYPTO_num_locks(); i++)
|
|
||||||
ppmutexOpenSSL[i] = new CCriticalSection();
|
|
||||||
CRYPTO_set_locking_callback(locking_callback);
|
CRYPTO_set_locking_callback(locking_callback);
|
||||||
|
|
||||||
// OpenSSL can optionally load a config file which lists optional loadable modules and engines.
|
// OpenSSL can optionally load a config file which lists optional loadable modules and engines.
|
||||||
@ -166,9 +164,8 @@ public:
|
|||||||
RAND_cleanup();
|
RAND_cleanup();
|
||||||
// Shutdown OpenSSL library multithreading support
|
// Shutdown OpenSSL library multithreading support
|
||||||
CRYPTO_set_locking_callback(NULL);
|
CRYPTO_set_locking_callback(NULL);
|
||||||
for (int i = 0; i < CRYPTO_num_locks(); i++)
|
// Clear the set of locks now to maintain symmetry with the constructor.
|
||||||
delete ppmutexOpenSSL[i];
|
ppmutexOpenSSL.reset();
|
||||||
OPENSSL_free(ppmutexOpenSSL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
instance_of_cinit;
|
instance_of_cinit;
|
||||||
|
Loading…
Reference in New Issue
Block a user