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 authored and F0bes committed Dec 3, 2024
1 parent 687c587 commit 07df874
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,
// when that happens, the connections vector gets modified via our close handler.
// Duplicate the vector to avoid iterating over a modified collection,
// this also avoids the issue of recursive locking when 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 07df874

Please sign in to comment.