Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPClient: Fix socket leak on connect failure #18749

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Common/Net/HTTPClient.cpp
Original file line number Diff line number Diff line change
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