mirror of
https://github.com/Genymobile/scrcpy
synced 2024-11-15 06:12:53 +00:00
Prevent socket leak on error
Signed-off-by: Yu-Chen Lin <npes87184@gmail.com> Signed-off-by: Romain Vimont <rom@rom1v.com>
This commit is contained in:
parent
fcf225049d
commit
a56045dd80
@ -33,6 +33,7 @@ net_connect(uint32_t addr, uint16_t port) {
|
||||
|
||||
if (connect(sock, (SOCKADDR *) &sin, sizeof(sin)) == SOCKET_ERROR) {
|
||||
perror("connect");
|
||||
close(sock);
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
@ -60,11 +61,13 @@ net_listen(uint32_t addr, uint16_t port, int backlog) {
|
||||
|
||||
if (bind(sock, (SOCKADDR *) &sin, sizeof(sin)) == SOCKET_ERROR) {
|
||||
perror("bind");
|
||||
close(sock);
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
if (listen(sock, backlog) == SOCKET_ERROR) {
|
||||
perror("listen");
|
||||
close(sock);
|
||||
return INVALID_SOCKET;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user