@@ -117,26 +117,24 @@ std::atomic<bool> fReopenDebugLog(false);
117
117
CTranslationInterface translationInterface;
118
118
119
119
/* * Init OpenSSL library multithreading support */
120
- static CCriticalSection** ppmutexOpenSSL;
120
+ static std::unique_ptr< CCriticalSection[]> ppmutexOpenSSL;
121
121
void locking_callback (int mode, int i, const char * file, int line) NO_THREAD_SAFETY_ANALYSIS
122
122
{
123
123
if (mode & CRYPTO_LOCK) {
124
- ENTER_CRITICAL_SECTION (* ppmutexOpenSSL[i]);
124
+ ENTER_CRITICAL_SECTION (ppmutexOpenSSL[i]);
125
125
} else {
126
- LEAVE_CRITICAL_SECTION (* ppmutexOpenSSL[i]);
126
+ LEAVE_CRITICAL_SECTION (ppmutexOpenSSL[i]);
127
127
}
128
128
}
129
129
130
- // Init
130
+ // Singleton for wrapping OpenSSL setup/teardown.
131
131
class CInit
132
132
{
133
133
public:
134
134
CInit ()
135
135
{
136
136
// Init OpenSSL library multithreading support
137
- ppmutexOpenSSL = (CCriticalSection**)OPENSSL_malloc (CRYPTO_num_locks () * sizeof (CCriticalSection*));
138
- for (int i = 0 ; i < CRYPTO_num_locks (); i++)
139
- ppmutexOpenSSL[i] = new CCriticalSection ();
137
+ ppmutexOpenSSL.reset (new CCriticalSection[CRYPTO_num_locks ()]);
140
138
CRYPTO_set_locking_callback (locking_callback);
141
139
142
140
// OpenSSL can optionally load a config file which lists optional loadable modules and engines.
@@ -160,9 +158,8 @@ class CInit
160
158
RAND_cleanup ();
161
159
// Shutdown OpenSSL library multithreading support
162
160
CRYPTO_set_locking_callback (NULL );
163
- for (int i = 0 ; i < CRYPTO_num_locks (); i++)
164
- delete ppmutexOpenSSL[i];
165
- OPENSSL_free (ppmutexOpenSSL);
161
+ // Clear the set of locks now to maintain symmetry with the constructor.
162
+ ppmutexOpenSSL.reset ();
166
163
}
167
164
}
168
165
instance_of_cinit;
0 commit comments