mirror of
https://github.com/FreeRDP/FreeRDP.git
synced 2024-12-04 15:23:32 +08:00
Fixed possible socket leak in tcp_connect, added disconnect function to properly clean-up socket/tls resources on disconnect)
This commit is contained in:
parent
d4ae0b376e
commit
36e929f69c
@ -344,6 +344,7 @@ int dfreerdp_run(freerdp* instance)
|
||||
freerdp_chanman_free(chanman);
|
||||
df_free(dfi);
|
||||
gdi_free(instance);
|
||||
instance->Disconnect(instance);
|
||||
freerdp_free(instance);
|
||||
|
||||
return 0;
|
||||
|
@ -597,6 +597,7 @@ int xfreerdp_run(freerdp* instance)
|
||||
|
||||
freerdp_chanman_close(chanman, instance);
|
||||
freerdp_chanman_free(chanman);
|
||||
instance->Disconnect(instance);
|
||||
freerdp_free(instance);
|
||||
xf_free(xfi);
|
||||
|
||||
|
@ -44,6 +44,7 @@ typedef boolean (*pcGetFileDescriptor)(freerdp* instance, void** rfds, int* rcou
|
||||
typedef boolean (*pcCheckFileDescriptor)(freerdp* instance);
|
||||
typedef int (*pcSendChannelData)(freerdp* instance, int channelId, uint8* data, int size);
|
||||
typedef int (*pcReceiveChannelData)(freerdp* instance, int channelId, uint8* data, int size, int flags, int total_size);
|
||||
typedef void (*pcDisconnect)(freerdp* instance);
|
||||
|
||||
struct rdp_freerdp
|
||||
{
|
||||
@ -64,6 +65,7 @@ struct rdp_freerdp
|
||||
pcCheckFileDescriptor CheckFileDescriptor;
|
||||
pcSendChannelData SendChannelData;
|
||||
pcReceiveChannelData ReceiveChannelData;
|
||||
pcDisconnect Disconnect;
|
||||
};
|
||||
|
||||
FREERDP_API freerdp* freerdp_new();
|
||||
|
@ -70,6 +70,14 @@ static int freerdp_send_channel_data(freerdp* instance, int channel_id, uint8* d
|
||||
return rdp_send_channel_data(instance->rdp, channel_id, data, size);
|
||||
}
|
||||
|
||||
void freerdp_disconnect(freerdp* instance)
|
||||
{
|
||||
rdpRdp* rdp;
|
||||
|
||||
rdp = (rdpRdp*) instance->rdp;
|
||||
transport_disconnect(rdp->transport);
|
||||
}
|
||||
|
||||
freerdp* freerdp_new()
|
||||
{
|
||||
freerdp* instance;
|
||||
@ -88,6 +96,7 @@ freerdp* freerdp_new()
|
||||
instance->GetFileDescriptor = freerdp_get_fds;
|
||||
instance->CheckFileDescriptor = freerdp_check_fds;
|
||||
instance->SendChannelData = freerdp_send_channel_data;
|
||||
instance->Disconnect = freerdp_disconnect;
|
||||
|
||||
input_register_client_callbacks(rdp->input);
|
||||
}
|
||||
|
@ -102,7 +102,6 @@ void tcp_get_mac_address(rdpTcp * tcp)
|
||||
boolean tcp_connect(rdpTcp* tcp, const char* hostname, uint16 port)
|
||||
{
|
||||
int status;
|
||||
int sockfd = -1;
|
||||
char servname[10];
|
||||
struct addrinfo hints = { 0 };
|
||||
struct addrinfo * res, * ai;
|
||||
@ -119,30 +118,31 @@ boolean tcp_connect(rdpTcp* tcp, const char* hostname, uint16 port)
|
||||
return False;
|
||||
}
|
||||
|
||||
tcp->sockfd = -1;
|
||||
for (ai = res; ai; ai = ai->ai_next)
|
||||
{
|
||||
sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
|
||||
tcp->sockfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
|
||||
|
||||
if (sockfd < 0)
|
||||
if (tcp->sockfd < 0)
|
||||
continue;
|
||||
|
||||
if (connect(sockfd, ai->ai_addr, ai->ai_addrlen) == 0)
|
||||
if (connect(tcp->sockfd, ai->ai_addr, ai->ai_addrlen) == 0)
|
||||
{
|
||||
printf("connected to %s:%s\n", hostname, servname);
|
||||
break;
|
||||
}
|
||||
|
||||
sockfd = -1;
|
||||
close(tcp->sockfd);
|
||||
tcp->sockfd = -1;
|
||||
}
|
||||
freeaddrinfo(res);
|
||||
|
||||
if (sockfd == -1)
|
||||
if (tcp->sockfd == -1)
|
||||
{
|
||||
printf("unable to connect to %s:%s\n", hostname, servname);
|
||||
return False;
|
||||
}
|
||||
|
||||
tcp->sockfd = sockfd;
|
||||
tcp_get_ip_address(tcp);
|
||||
tcp_get_mac_address(tcp);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user