Skip to content

Commit

Permalink
DEV9: Fix race-condition while handling closed connection
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastRar authored and F0bes committed Dec 5, 2024
1 parent f317ba3 commit f91f39a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pcsx2/DEV9/ThreadSafeMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class ThreadSafeMap
map[key] = value;
}

void Remove(Key key)
bool Remove(Key key)
{
std::unique_lock modifyLock(accessMutex);
map.erase(key);
return map.erase(key) == 1;
}

void Clear()
Expand Down
6 changes: 4 additions & 2 deletions pcsx2/DEV9/sockets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,8 @@ int SocketAdapter::SendFromConnection(ConnectionKey Key, IP_Packet* ipPkt)
void SocketAdapter::HandleConnectionClosed(BaseSession* sender)
{
const ConnectionKey key = sender->key;
connections.Remove(key);
if (!connections.Remove(key))
return;

// Defer deleting the connection untill we have left the calling session's callstack
if (std::this_thread::get_id() == sendThreadId)
Expand Down Expand Up @@ -558,7 +559,8 @@ void SocketAdapter::HandleConnectionClosed(BaseSession* sender)
void SocketAdapter::HandleFixedPortClosed(BaseSession* sender)
{
const ConnectionKey key = sender->key;
connections.Remove(key);
if (!connections.Remove(key))
return;
fixedUDPPorts.Remove(key.ps2Port);

// Defer deleting the connection untill we have left the calling session's callstack
Expand Down

0 comments on commit f91f39a

Please sign in to comment.