[Libwebsockets] openssl-tls.c

Mykola Stryebkov mykola.stryebkov at icloud.com
Thu Apr 8 13:55:27 CEST 2021


Hi,

In some weird cases function lws_context_deinit_ssl_library() is called twice (I believe it’s my fault, but anyway).

I propose the following patch to prevent second free attempt:
==================================================
diff --git a/lib/tls/openssl/openssl-tls.c b/lib/tls/openssl/openssl-tls.c
index e79e6d1d..de44a34e 100644
--- a/lib/tls/openssl/openssl-tls.c
+++ b/lib/tls/openssl/openssl-tls.c
@@ -93,7 +93,7 @@ lws_tls_err_describe_clear(void)
 
 #if LWS_MAX_SMP != 1
 
-static pthread_mutex_t *openssl_mutexes;
+static pthread_mutex_t *openssl_mutexes = NULL;
 
 static void
 lws_openssl_lock_callback(int mode, int type, const char *file, int line)
@@ -203,9 +203,13 @@ lws_context_deinit_ssl_library(struct lws_context *context)
 
        CRYPTO_set_locking_callback(NULL);
 
-       for (n = 0; n < CRYPTO_num_locks(); n++)
-               pthread_mutex_destroy(&openssl_mutexes[n]);
+  if(openssl_mutexes)
+  {
+    for (n = 0; n < CRYPTO_num_locks(); n++)
+      pthread_mutex_destroy(&openssl_mutexes[n]);
 
-       OPENSSL_free(openssl_mutexes);
+    OPENSSL_free(openssl_mutexes);
+    openssl_mutexes = NULL;
+  }
 #endif
 }
==================================================

— 
With respect, M.
Public GnuPG key: 0x01731B47DBD56C0F
fpr: 0226 54EE C1FF 8636 36EF  2AC9 BCE9 CFC7 9CF4 6747

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20210408/a36a4c18/attachment.htm>


More information about the Libwebsockets mailing list