code cleanup, memleak fixed on the client side;

v0.5.xx
Alexander Vdolainen 9 years ago
parent ef36409851
commit 56a6f24df1

@ -35,6 +35,7 @@
#include <openssl/ssl.h> #include <openssl/ssl.h>
#include <openssl/err.h> #include <openssl/err.h>
#include <openssl/engine.h>
#include <tdata/usrtc.h> #include <tdata/usrtc.h>
#include <tdata/list.h> #include <tdata/list.h>
@ -385,6 +386,11 @@ void sntl_finalize(void)
OPENSSL_free(lock_cs); OPENSSL_free(lock_cs);
OPENSSL_free(lock_count); OPENSSL_free(lock_count);
ERR_free_strings();
ENGINE_cleanup();
CRYPTO_cleanup_all_ex_data();
EVP_cleanup();
return; return;
} }
@ -544,6 +550,7 @@ static void __connection_destroy(conn_t *co)
/* free queue */ /* free queue */
ERR_remove_state(0); ERR_remove_state(0);
ERR_remove_thread_state(0);
/* update use count */ /* update use count */
usleep(1500); usleep(1500);
@ -580,28 +587,18 @@ static void __connection_destroy(conn_t *co)
if(co->pctx->login) free(co->pctx->login); if(co->pctx->login) free(co->pctx->login);
if(co->pctx->passwd) free(co->pctx->passwd); 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); SSL_set_shutdown(co->ssl, SSL_RECEIVED_SHUTDOWN | SSL_SENT_SHUTDOWN);
fd = SSL_get_fd(co->ssl); 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_free(co->ssl);
//SSL_CTX_free(co->ssys->ctx);
co->ssl = NULL; co->ssl = NULL;
ERR_remove_thread_state(0); ERR_remove_thread_state(0);
ERR_remove_state(0); ERR_remove_state(0);
//ENGINE_cleanup();
//CRYPTO_cleanup_all_ex_data();
ERR_free_strings(); ERR_free_strings();
//ERR_remove_state(0);
//EVP_cleanup();
// ENGINE_cleanup();
close(fd); close(fd);
__connection_second_free(co); __connection_second_free(co);
@ -1327,7 +1324,10 @@ conn_t *connection_link(conn_sys_t *ssys, const char *host,
if(!bundle) goto __fail5; if(!bundle) goto __fail5;
r = pthread_create(&co->thrd_poll[i], NULL, __sntll_thread, bundle); r = pthread_create(&co->thrd_poll[i], NULL, __sntll_thread, bundle);
if(r) goto __fail5; if(r) goto __fail5;
else bundle = (void *)0xdead; else {
pthread_detach(co->thrd_poll[i]);
bundle = (void *)0xdead;
}
} }
/* all is done, connection now ready */ /* all is done, connection now ready */
@ -1345,6 +1345,9 @@ conn_t *connection_link(conn_sys_t *ssys, const char *host,
__fail2: __fail2:
if(buf != MAP_FAILED) munmap(buf, 65536); if(buf != MAP_FAILED) munmap(buf, 65536);
SSL_shutdown(co->ssl); SSL_shutdown(co->ssl);
ERR_remove_thread_state(0);
ERR_remove_state(0);
close(sck); close(sck);
__fail: __fail:
if(co) { if(co) {

Loading…
Cancel
Save