Description: Explicitly call OPENSSL_cleanup() on TLS module destruction
 Older OpenSSL releases do not perform automatic cleanup on exit, newer ones
 do via an atexit() handler.
 .
 In addition the OpenSSL code leaks (on purpose) a DSO handler for itself so
 that it can guarantee that the library is still present when the atexit()
 handler is executed.
 .
 When the handler is called, a pthreads variable is still present but the
 memory it points to is not allocated anymore, which indicates something else
 released those pthreads pools. Most probably pthreads itself as part of its
 deconstructors or atexit() handlers while being unloaded.
 .
 While that's a bug that should be tracked independently. Explicitly calling
 the OpenSSL cleanup code fixes the issue for newer OpenSSL releases and is
 something that would be needed anyway on older OpenSSL releases.
Origin: other, Sipwise
Author: Guillem Jover <gjover@sipwise.com>
Bug-Debian: https://bugs.debian.org/870018

---

--- kamailio-5.0.2.orig/src/modules/tls/tls_init.c
+++ kamailio-5.0.2/src/modules/tls/tls_init.c
@@ -778,4 +778,6 @@ void destroy_tls_h(void)
 	tls_destroy_cfg();
 	tls_destroy_locks();
 	tls_ct_wq_destroy();
+
+	OPENSSL_cleanup();
 }
