From 7c42966f14a2499b0c6b187be9f705e0710a19c5 Mon Sep 17 00:00:00 2001 From: Image <> Date: Wed, 25 Mar 2020 23:15:48 -0400 Subject: [PATCH] Fixed erase crash when no client to erase --- EQ2/source/WorldServer/zoneserver.cpp | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/EQ2/source/WorldServer/zoneserver.cpp b/EQ2/source/WorldServer/zoneserver.cpp index 5bdc1eb5b..8be6cf660 100644 --- a/EQ2/source/WorldServer/zoneserver.cpp +++ b/EQ2/source/WorldServer/zoneserver.cpp @@ -2903,7 +2903,9 @@ void ZoneServer::RemoveClientImmediately(Client* client) { guild->GuildMemberLogoff(client->GetPlayer()); MClientList.writelock(__FUNCTION__, __LINE__); - clients.erase(find(clients.begin(), clients.end(), client)); + std::vector<Client*>::iterator itr = find(clients.begin(), clients.end(), client); + if (itr != clients.end()) + clients.erase(itr); MClientList.releasewritelock(__FUNCTION__, __LINE__); //clients.Remove(client); LogWrite(ZONE__INFO, 0, "Zone", "Removing connection for client '%s'.", client->GetPlayer()->GetName()); @@ -2912,7 +2914,9 @@ void ZoneServer::RemoveClientImmediately(Client* client) { else { MClientList.writelock(__FUNCTION__, __LINE__); - clients.erase(find(clients.begin(), clients.end(), client)); + std::vector<Client*>::iterator itr = find(clients.begin(), clients.end(), client); + if (itr != clients.end()) + clients.erase(itr); MClientList.releasewritelock(__FUNCTION__, __LINE__); //clients.Remove(client, true); } @@ -3678,38 +3682,27 @@ void ZoneServer::RemoveSpawn(bool spawnListLocked, Spawn* spawn, bool delete_spa if (reloading) RemoveDeadEnemyList(spawn); - LogWrite(ZONE__DEBUG, 7, "Zone", "Lock DeadSpawns..."); - if (lock) MDeadSpawns.writelock(__FUNCTION__, __LINE__); - LogWrite(ZONE__DEBUG, 7, "Zone", "Erase DeadSpawns..."); if (dead_spawns.count(spawn->GetID()) > 0) dead_spawns.erase(spawn->GetID()); if (lock) MDeadSpawns.releasewritelock(__FUNCTION__, __LINE__); - LogWrite(ZONE__DEBUG, 7, "Zone", "End DeadSpawns..."); - - - LogWrite(ZONE__DEBUG, 7, "Zone", "SpawnExpireTimers..."); if (spawn_expire_timers.count(spawn->GetID()) > 0) spawn_expire_timers.erase(spawn->GetID()); - LogWrite(ZONE__DEBUG, 7, "Zone", "SpawnExpireTimers Done..."); RemoveDelayedSpawnRemove(spawn); - LogWrite(ZONE__DEBUG, 7, "Zone", "RemoveDelayedSpawnRemove Done..."); // Clear the pointer in the spawn list, spawn thread will remove the key if (!spawnListLocked) MSpawnList.writelock(__FUNCTION__, __LINE__); - LogWrite(ZONE__DEBUG, 7, "Zone", "RemoveSpawnList Start..."); spawn_list.erase(spawn->GetID()); if (!spawnListLocked) MSpawnList.releasewritelock(__FUNCTION__, __LINE__); - LogWrite(ZONE__DEBUG, 7, "Zone", "RemoveSpawnList Done..."); PacketStruct* packet = 0; int16 packet_version = 0; @@ -3717,7 +3710,6 @@ void ZoneServer::RemoveSpawn(bool spawnListLocked, Spawn* spawn, bool delete_spa vector<Client*>::iterator client_itr; - LogWrite(ZONE__DEBUG, 7, "Zone", "ClientList Start..."); MClientList.readlock(__FUNCTION__, __LINE__); for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) { client = *client_itr; @@ -3740,8 +3732,6 @@ void ZoneServer::RemoveSpawn(bool spawnListLocked, Spawn* spawn, bool delete_spa } MClientList.releasereadlock(__FUNCTION__, __LINE__); - LogWrite(ZONE__DEBUG, 7, "Zone", "ClientList End..."); - safe_delete(packet); if(respawn && !spawn->IsPlayer() && spawn->GetRespawnTime() > 0 && spawn->GetSpawnLocationID() > 0)