aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Snider <tjps636@gmail.com>2017-03-22 15:34:33 -0700
committerThomas Snider <tjps636@gmail.com>2017-03-28 17:36:31 -0700
commit6d5dd60c881b790f1b5fc5ba470605b6bd7e2fe7 (patch)
tree304184be11a20aea41a4e8ebd58b6a29ccedf901 /src
parent02d64bd929c9663ba38e96721c6dbd89972d043d (diff)
downloadbitcoin-6d5dd60c881b790f1b5fc5ba470605b6bd7e2fe7.tar.xz
No need to use OpenSSL malloc/free
Diffstat (limited to 'src')
-rw-r--r--src/util.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 486df772fb..694fb184c1 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -117,26 +117,24 @@ std::atomic<bool> fReopenDebugLog(false);
CTranslationInterface translationInterface;
/** 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
{
if (mode & CRYPTO_LOCK) {
- ENTER_CRITICAL_SECTION(*ppmutexOpenSSL[i]);
+ ENTER_CRITICAL_SECTION(ppmutexOpenSSL[i]);
} else {
- LEAVE_CRITICAL_SECTION(*ppmutexOpenSSL[i]);
+ LEAVE_CRITICAL_SECTION(ppmutexOpenSSL[i]);
}
}
-// Init
+// Singleton for wrapping OpenSSL setup/teardown.
class CInit
{
public:
CInit()
{
// Init OpenSSL library multithreading support
- ppmutexOpenSSL = (CCriticalSection**)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(CCriticalSection*));
- for (int i = 0; i < CRYPTO_num_locks(); i++)
- ppmutexOpenSSL[i] = new CCriticalSection();
+ ppmutexOpenSSL.reset(new CCriticalSection[CRYPTO_num_locks()]);
CRYPTO_set_locking_callback(locking_callback);
// OpenSSL can optionally load a config file which lists optional loadable modules and engines.
@@ -160,9 +158,8 @@ public:
RAND_cleanup();
// Shutdown OpenSSL library multithreading support
CRYPTO_set_locking_callback(NULL);
- for (int i = 0; i < CRYPTO_num_locks(); i++)
- delete ppmutexOpenSSL[i];
- OPENSSL_free(ppmutexOpenSSL);
+ // Clear the set of locks now to maintain symmetry with the constructor.
+ ppmutexOpenSSL.reset();
}
}
instance_of_cinit;