<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hi Matt,<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">Am 16.04.2020 um 16:29 schrieb Matt Caswell <<a href="mailto:matt@openssl.org" class="">matt@openssl.org</a>>:</div><div class=""><div class="">On 16/04/2020 14:42, Harald Koch wrote:<br class=""><blockquote type="cite" class="">Hello list,<br class=""><br class="">I have a TLS server which is started on demand in a multithreaded (pthread) application. The TLS server is one thread which is being started and stopped. At first start, the TLS server initialized with SSL_CTX_new with TLS_server_method works as expected, after cleaning up, eliminating the thread and starting it again at a later time in the same process, SSL_CTX_new returns NULL. I’ve been digging deeper into the initialization code, and found out that in crypto/threads_pthread.c, function<br class=""></blockquote>What does your clean up code look like? Are you taking specific steps to<br class="">cleanup OpenSSL and if so what are they?<br class=""></div></div></blockquote><div><br class=""></div><div>I’m checking if my actually used SSL and CTX are up, and if so, cleanup them before thread killing:</div><div><br class=""></div><div><div>    if(ssl != NULL) { // assigned by SSL_new before</div><div>        SSL_free(ssl);</div><div>        ssl = NULL;</div><div>    }</div><div>    /* Free the SSL_CTX structure */</div><div>    if(ctx != NULL) { // assigned by SSL_CTX_new before</div><div>        SSL_CTX_free(ctx);</div><div>        ctx = NULL;</div><div>    }</div><div class=""><br class=""></div><div class="">No other openSSL specific cleanup functions are called. The functions documented in <a href="https://wiki.openssl.org/index.php/Library_Initialization#Cleanup" class="">https://wiki.openssl.org/index.php/Library_Initialization#Cleanup</a> are not called.</div></div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class="">CRYPTO_THREAD_set_local the call to pthread_setspecific returns a value<br class="">!= 0 (in my case: 22). The error queue of openSSL stays empty. The same<br class="">code works with openSSL 1.1.0 in all versions.<br class=""><blockquote type="cite" class="">Some posts googled state that before usage, be sure to run OPENSSL_init_ssl (which I do, even if not required to my analysis since it’s already called in one of the called functions deeper in the library).<br class="">Am I missing something in a multithreaded environment?<br class=""></blockquote></div></div></blockquote></div><br class=""></body></html>