Skip to content

Commit

Permalink
DEV9: Avoid iterating over modified vector in UDP_FixedPort
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastRar committed Nov 28, 2024
1 parent 6d58819 commit 8ad69b9
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions pcsx2/DEV9/Sessions/UDP_Session/UDP_FixedPort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,18 @@ namespace Sessions

void UDP_FixedPort::Reset()
{
std::lock_guard numberlock(connectionSentry);
// Reseting a session may cause that session to close itself,
// hen that happens, connections gets modified via our close handler.
// Duplicate the vector to avoid iterating over a modified collection.
// We also avoid the issue of recursive locking (our close handler takes a lock).
std::vector<UDP_BaseSession*> connectionsCopy;
{
std::lock_guard numberlock(connectionSentry);
connectionsCopy = connections;
}

for (size_t i = 0; i < connections.size(); i++)
connections[i]->Reset();
for (size_t i = 0; i < connectionsCopy.size(); i++)
connectionsCopy[i]->Reset();
}

UDP_Session* UDP_FixedPort::NewClientSession(ConnectionKey parNewKey, bool parIsBrodcast, bool parIsMulticast)
Expand Down

0 comments on commit 8ad69b9

Please sign in to comment.