[Loginserver] Fix iterator crash (#4670)

This commit is contained in:
Chris Miles 2025-02-11 21:22:56 -06:00 committed by GitHub
parent 843f6531a7
commit 59292b15f6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -199,7 +199,8 @@ ClientManager::ClientManager()
); );
} }
ClientManager::~ClientManager() { ClientManager::~ClientManager()
{
delete m_titanium_stream; delete m_titanium_stream;
delete m_titanium_ops; delete m_titanium_ops;
delete m_sod_stream; delete m_sod_stream;
@ -210,53 +211,49 @@ void ClientManager::Process()
{ {
ProcessDisconnect(); ProcessDisconnect();
m_clients.erase( for (auto it = m_clients.begin(); it != m_clients.end();) {
std::remove_if( Client *c = *it;
m_clients.begin(), m_clients.end(), if (!c->Process()) {
[](Client *c) { LogWarning("Client had a fatal error and had to be removed from the login");
if (!c->Process()) { delete c;
LogWarning("Client had a fatal error and had to be removed from the login"); it = m_clients.erase(it);
delete c; }
return true; else {
} ++it;
return false; }
} }
),
m_clients.end());
} }
void ClientManager::ProcessDisconnect() void ClientManager::ProcessDisconnect()
{ {
m_clients.erase( auto it = m_clients.begin();
std::remove_if( while (it != m_clients.end()) {
m_clients.begin(), m_clients.end(), Client *c = *it;
[](Client *c) { if (c->GetConnection()->CheckState(CLOSED)) {
if (c->GetConnection()->CheckState(CLOSED)) { LogInfo("Client disconnected from the server, removing client");
LogInfo("Client disconnected from the server, removing client"); delete c;
delete c; it = m_clients.erase(it);
return true; }
} else {
return false; ++it;
} }
), }
m_clients.end());
} }
void ClientManager::RemoveExistingClient(unsigned int account_id, const std::string &loginserver) void ClientManager::RemoveExistingClient(unsigned int account_id, const std::string &loginserver)
{ {
m_clients.erase( auto it = m_clients.begin();
std::remove_if( while (it != m_clients.end()) {
m_clients.begin(), m_clients.end(), Client *c = *it;
[&](Client *c) { if (c->GetAccountID() == account_id && c->GetLoginServerName() == loginserver) {
if (c->GetAccountID() == account_id && c->GetLoginServerName() == loginserver) { LogInfo("Client attempting to log in existing client already logged in, removing existing client");
LogInfo("Client attempting to log in existing client already logged in, removing existing client"); delete c;
delete c; it = m_clients.erase(it);
return true; }
} else {
return false; ++it;
} }
), }
m_clients.end());
} }
Client *ClientManager::GetClient(unsigned int account_id, const std::string &loginserver) Client *ClientManager::GetClient(unsigned int account_id, const std::string &loginserver)