Fix socket errors being clobbered by closeSocket()

This commit is contained in:
Cameron Gutman 2020-08-28 18:48:15 -07:00
parent 5ddd53e17f
commit e74fe2b016

View File

@ -53,6 +53,8 @@ int LiFindExternalAddressIP4(const char* stunServer, unsigned short stunPort, un
char buf[1024]; char buf[1024];
} resp; } resp;
sock = INVALID_SOCKET;
err = initializePlatformSockets(); err = initializePlatformSockets();
if (err != 0) { if (err != 0) {
Limelog("Failed to initialize sockets: %d\n", err); Limelog("Failed to initialize sockets: %d\n", err);
@ -111,8 +113,6 @@ int LiFindExternalAddressIP4(const char* stunServer, unsigned short stunPort, un
} }
} }
closeSocket(sock);
if (bytesRead == 0) { if (bytesRead == 0) {
Limelog("No response from STUN server\n"); Limelog("No response from STUN server\n");
err = -2; err = -2;
@ -183,6 +183,10 @@ int LiFindExternalAddressIP4(const char* stunServer, unsigned short stunPort, un
err = -6; err = -6;
Exit: Exit:
if (sock != INVALID_SOCKET) {
closeSocket(sock);
}
if (stunAddrs != NULL) { if (stunAddrs != NULL) {
freeaddrinfo(stunAddrs); freeaddrinfo(stunAddrs);
} }