From 46724b0c754334194d231ff75e902adda384dd42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Wed, 11 Feb 2015 10:57:14 -0500 Subject: [PATCH] libfreerdp-core: fix tsg crash on disconnect --- libfreerdp/core/tcp.c | 14 +--------- libfreerdp/core/tcp.h | 1 - libfreerdp/core/transport.c | 55 +++++++++++++++++++++---------------- 3 files changed, 33 insertions(+), 37 deletions(-) diff --git a/libfreerdp/core/tcp.c b/libfreerdp/core/tcp.c index 2aee437d4..5dca53165 100644 --- a/libfreerdp/core/tcp.c +++ b/libfreerdp/core/tcp.c @@ -337,6 +337,7 @@ static int transport_bio_simple_uninit(BIO* bio) { if (bio->init) { + _shutdown(ptr->socket, SD_BOTH); closesocket(ptr->socket); ptr->socket = 0; } @@ -1123,19 +1124,6 @@ BOOL freerdp_tcp_connect(rdpTcp* tcp, const char* hostname, int port, int timeou return TRUE; } -BOOL freerdp_tcp_disconnect(rdpTcp* tcp) -{ - if (tcp->sockfd != -1) - { - shutdown(tcp->sockfd, SHUT_RDWR); - close(tcp->sockfd); - - tcp->sockfd = -1; - } - - return TRUE; -} - BOOL freerdp_tcp_set_blocking_mode(rdpTcp* tcp, BOOL blocking) { return BIO_set_nonblock(tcp->socketBio, blocking ? 0 : 1) ? TRUE : FALSE; diff --git a/libfreerdp/core/tcp.h b/libfreerdp/core/tcp.h index 1dceeb7a8..55106edc1 100644 --- a/libfreerdp/core/tcp.h +++ b/libfreerdp/core/tcp.h @@ -70,7 +70,6 @@ struct rdp_tcp }; BOOL freerdp_tcp_connect(rdpTcp* tcp, const char* hostname, int port, int timeout); -BOOL freerdp_tcp_disconnect(rdpTcp* tcp); int freerdp_tcp_read(rdpTcp* tcp, BYTE* data, int length); int freerdp_tcp_write(rdpTcp* tcp, BYTE* data, int length); int freerdp_tcp_wait_read(rdpTcp* tcp, DWORD dwMilliSeconds); diff --git a/libfreerdp/core/transport.c b/libfreerdp/core/transport.c index 12798eb5b..a999deaa4 100644 --- a/libfreerdp/core/transport.c +++ b/libfreerdp/core/transport.c @@ -100,36 +100,44 @@ BOOL transport_disconnect(rdpTransport* transport) transport_stop(transport); - if (transport->TlsIn) - tls_free(transport->TlsIn); + if (transport->tsg) + { + if (transport->TsgTls) + { + tls_free(transport->TsgTls); + transport->TsgTls = NULL; + } - if (transport->TlsOut != transport->TlsIn) - tls_free(transport->TlsOut); + tsg_free(transport->tsg); + transport->tsg = NULL; + + if (transport->TlsIn) + tls_free(transport->TlsIn); + + if (transport->TcpIn) + freerdp_tcp_free(transport->TcpIn); + + if (transport->TlsOut) + tls_free(transport->TlsOut); + + if (transport->TcpOut) + freerdp_tcp_free(transport->TcpOut); + } + else + { + if (transport->TlsIn) + tls_free(transport->TlsIn); + + if (transport->TcpIn) + freerdp_tcp_free(transport->TcpIn); + } transport->TlsIn = NULL; transport->TlsOut = NULL; - if (transport->tsg) - { - tsg_free(transport->tsg); - transport->tsg = NULL; - } - - if (transport->TcpOut && (transport->TcpOut != transport->TcpIn)) { - freerdp_tcp_disconnect(transport->TcpOut); - freerdp_tcp_free(transport->TcpOut); - } - + transport->TcpIn = NULL; transport->TcpOut = NULL; - if (transport->TsgTls) - { - tls_free(transport->TsgTls); - transport->TsgTls = NULL; - } - - freerdp_tcp_disconnect(transport->TcpIn); - transport->layer = TRANSPORT_LAYER_TCP; return status; @@ -1168,5 +1176,6 @@ void transport_free(rdpTransport* transport) CloseHandle(transport->connectedEvent); DeleteCriticalSection(&(transport->ReadLock)); DeleteCriticalSection(&(transport->WriteLock)); + free(transport); }