|
|
@@ -2063,15 +2063,17 @@ int main(int argc, char **argv)
|
|
|
|
|
|
#if defined(OPENSSL_THREADS)
|
|
|
|
|
|
-static pthread_mutex_t* mutex_buf = NULL;
|
|
|
+static pthread_mutex_t** mutex_buf = NULL;
|
|
|
|
|
|
static void locking_function(int mode, int n, const char *file, int line) {
|
|
|
UNUSED_ARG(file);
|
|
|
UNUSED_ARG(line);
|
|
|
- if (mode & CRYPTO_LOCK)
|
|
|
- pthread_mutex_lock(&mutex_buf[n]);
|
|
|
- else
|
|
|
- pthread_mutex_unlock(&mutex_buf[n]);
|
|
|
+ if(mutex_buf && (n < CRYPTO_num_locks()) && mutex_buf[n]) {
|
|
|
+ if (mode & CRYPTO_LOCK)
|
|
|
+ pthread_mutex_lock(mutex_buf[n]);
|
|
|
+ else
|
|
|
+ pthread_mutex_unlock(mutex_buf[n]);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x10000000L
|
|
|
@@ -2094,12 +2096,13 @@ static int THREAD_setup(void) {
|
|
|
|
|
|
int i;
|
|
|
|
|
|
- mutex_buf = (pthread_mutex_t*) turn_malloc(CRYPTO_num_locks()
|
|
|
- * sizeof(pthread_mutex_t));
|
|
|
+ mutex_buf = (pthread_mutex_t**) turn_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t*));
|
|
|
if (!mutex_buf)
|
|
|
return 0;
|
|
|
- for (i = 0; i < CRYPTO_num_locks(); i++)
|
|
|
- pthread_mutex_init(&mutex_buf[i], NULL);
|
|
|
+ for (i = 0; i < CRYPTO_num_locks(); i++) {
|
|
|
+ mutex_buf[i] = (pthread_mutex_t*) turn_malloc(sizeof(pthread_mutex_t));
|
|
|
+ pthread_mutex_init(mutex_buf[i], NULL);
|
|
|
+ }
|
|
|
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x10000000L
|
|
|
CRYPTO_THREADID_set_callback(id_function);
|
|
|
@@ -2130,9 +2133,14 @@ int THREAD_cleanup(void) {
|
|
|
#endif
|
|
|
|
|
|
CRYPTO_set_locking_callback(NULL);
|
|
|
- for (i = 0; i < CRYPTO_num_locks(); i++)
|
|
|
- pthread_mutex_destroy(&mutex_buf[i]);
|
|
|
- turn_free(mutex_buf,sizeof(pthread_mutex_t));
|
|
|
+ for (i = 0; i < CRYPTO_num_locks(); i++) {
|
|
|
+ if(mutex_buf[i]) {
|
|
|
+ pthread_mutex_destroy(mutex_buf[i]);
|
|
|
+ turn_free(mutex_buf[i],sizeof(pthread_mutex_t));
|
|
|
+ mutex_buf[i] = NULL;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ turn_free(mutex_buf,CRYPTO_num_locks() * sizeof(pthread_mutex_t*));
|
|
|
mutex_buf = NULL;
|
|
|
|
|
|
#endif
|