Skip to content

Commit

Permalink
Merge pull request #18749 from hrydgard/fix-socket-leak
Browse files Browse the repository at this point in the history
HTTPClient: Fix socket leak on connect failure
  • Loading branch information
hrydgard committed Jan 23, 2024
2 parents 3fae8dd + deffbea commit 117b7ca
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions Common/Net/HTTPClient.cpp
Expand Up @@ -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.)
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 117b7ca

Please sign in to comment.