diff --git a/pcsx2/DEV9/ThreadSafeMap.h b/pcsx2/DEV9/ThreadSafeMap.h index 131e23312b..7409d7ca9c 100644 --- a/pcsx2/DEV9/ThreadSafeMap.h +++ b/pcsx2/DEV9/ThreadSafeMap.h @@ -37,10 +37,10 @@ public: 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() diff --git a/pcsx2/DEV9/sockets.cpp b/pcsx2/DEV9/sockets.cpp index 21aeb4a797..fbd73f1cc4 100644 --- a/pcsx2/DEV9/sockets.cpp +++ b/pcsx2/DEV9/sockets.cpp @@ -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) @@ -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