aboutsummaryrefslogtreecommitdiffstats
path: root/community/hermes/openssl-1.1.patch
blob: 85034a34fe1e19827dd16700166edde030d3bdd5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
diff --git a/src/hermes.cpp b/src/hermes.cpp
index edfe833..35b4062 100644
--- a/src/hermes.cpp
+++ b/src/hermes.cpp
@@ -63,12 +63,14 @@ __thread unsigned long connection_id;
 list<unsigned long> children;
 
 #ifdef HAVE_SSL
-pthread_mutex_t ssl_locks[CRYPTO_NUM_LOCKS]={PTHREAD_MUTEX_INITIALIZER};
+#define CRYPTO_NUM_LOCKS 100
+pthread_mutex_t *ssl_locks;
 
 void ssl_locking_function(int mode,int n,const char *file,int line)
 {
-  if(n>CRYPTO_NUM_LOCKS)
-    throw Exception(_("Error, "+Utils::inttostr(n)+" is bigger than CRYPTO_NUM_LOCKS("+Utils::inttostr(CRYPTO_NUM_LOCKS)+")"),__FILE__,__LINE__);
+  int num_locks = CRYPTO_num_locks();
+  if(n>num_locks)
+    throw Exception(_("Error, "+Utils::inttostr(n)+" is bigger than CRYPTO_NUM_LOCKS("+Utils::inttostr(num_locks)+")"),__FILE__,__LINE__);
   if(mode&CRYPTO_LOCK)
     pthread_mutex_lock(&ssl_locks[n]);
   else
@@ -94,6 +96,11 @@ main
   */
 
   #ifdef HAVE_SSL
+    int num_locks=CRYPTO_num_locks();
+    ssl_locks = (pthread_mutex_t *)calloc(num_locks, sizeof (*ssl_locks));
+    for (int i=0; i< num_locks; i++)
+      pthread_mutex_init(&ssl_locks[i], NULL);
+
     CRYPTO_set_locking_callback(ssl_locking_function);
     #ifndef WIN32 //getpid() returns different values for threads on windows, therefor this is not needed
     CRYPTO_set_id_callback(pthread_self);