HTTPClient: Fix socket leak on connect failure

This commit is contained in:
Henrik Rydgård
2024-01-23 11:05:03 +01:00
parent 3fae8dd547
commit deffbea75f
+13
View File
@@ -127,6 +127,14 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) {
ERROR_LOG(IO, "Bad socket");
continue;
}
// Windows sockets aren't limited by socket number, just by count, so checking FD_SETSIZE there is wrong.
#if !PPSSPP_PLATFORM(WINDOWS)
if (sock >= FD_SETSIZE) {
ERROR_LOG(IO, "Socket doesn't fit in FD_SET: %d We probably have a leak.", sock);
closesocket(sock);
continue;
}
#endif
fd_util::SetNonBlocking(sock, true);
// Start trying to connect (async with timeout.)
@@ -194,6 +202,11 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) {
// Great, now we're good to go.
return true;
} else {
// Fail. Close all the sockets.
for (int sock : sockets) {
closesocket(sock);
}
}
if (cancelConnect && *cancelConnect) {