diff --git a/lib/sntllv2.c b/lib/sntllv2.c index a3b6668..64532fc 100644 --- a/lib/sntllv2.c +++ b/lib/sntllv2.c @@ -35,6 +35,7 @@ #include #include +#include #include #include @@ -385,6 +386,11 @@ void sntl_finalize(void) OPENSSL_free(lock_cs); OPENSSL_free(lock_count); + ERR_free_strings(); + ENGINE_cleanup(); + CRYPTO_cleanup_all_ex_data(); + EVP_cleanup(); + return; } @@ -544,6 +550,7 @@ static void __connection_destroy(conn_t *co) /* free queue */ ERR_remove_state(0); + ERR_remove_thread_state(0); /* update use count */ usleep(1500); @@ -580,28 +587,18 @@ static void __connection_destroy(conn_t *co) if(co->pctx->login) free(co->pctx->login); if(co->pctx->passwd) free(co->pctx->passwd); - /*while((fd = SSL_shutdown(co->ssl)) != 1) { - if(fd < 0) break; - }*/ SSL_set_shutdown(co->ssl, SSL_RECEIVED_SHUTDOWN | SSL_SENT_SHUTDOWN); fd = SSL_get_fd(co->ssl); - //int ti = CRYPTO_add(&co->ssl->references, -1, CRYPTO_LOCK_SSL); - //printf("ti = %d;\n", ti); + SSL_free(co->ssl); - //SSL_CTX_free(co->ssys->ctx); co->ssl = NULL; ERR_remove_thread_state(0); ERR_remove_state(0); - //ENGINE_cleanup(); - //CRYPTO_cleanup_all_ex_data(); ERR_free_strings(); - //ERR_remove_state(0); - //EVP_cleanup(); - // ENGINE_cleanup(); close(fd); __connection_second_free(co); @@ -1327,7 +1324,10 @@ conn_t *connection_link(conn_sys_t *ssys, const char *host, if(!bundle) goto __fail5; r = pthread_create(&co->thrd_poll[i], NULL, __sntll_thread, bundle); if(r) goto __fail5; - else bundle = (void *)0xdead; + else { + pthread_detach(co->thrd_poll[i]); + bundle = (void *)0xdead; + } } /* all is done, connection now ready */ @@ -1345,6 +1345,9 @@ conn_t *connection_link(conn_sys_t *ssys, const char *host, __fail2: if(buf != MAP_FAILED) munmap(buf, 65536); SSL_shutdown(co->ssl); + ERR_remove_thread_state(0); + ERR_remove_state(0); + close(sck); __fail: if(co) {