From a584e25bf303840aa25a84a410242117bd5e6d58 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Wed, 31 Mar 2021 14:44:50 +0200 Subject: [PATCH] fix deadlock in DeleteCar --- include/Client.h | 1 - src/Client.cpp | 14 ++------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/include/Client.h b/include/Client.h index 2f85991..260071c 100644 --- a/include/Client.h +++ b/include/Client.h @@ -31,7 +31,6 @@ public: void SetName(const std::string& Name) { mName = Name; } void SetRoles(const std::string& Role) { mRole = Role; } void AddIdentifier(const std::string& ID) { mIdentifiers.insert(ID); }; - void EraseVehicle(TVehicleData& VehicleData); std::string GetCarData(int Ident); void SetUDPAddr(sockaddr_in Addr) { mUDPAddress = Addr; } void SetDownSock(SOCKET CSock) { mSocket[1] = CSock; } diff --git a/src/Client.cpp b/src/Client.cpp index fbdade3..e50e99c 100644 --- a/src/Client.cpp +++ b/src/Client.cpp @@ -6,24 +6,14 @@ // FIXME: add debug prints void TClient::DeleteCar(int Ident) { - std::unique_lock lock(mVehicleDataMutex); - for (auto& v : mVehicleData) { - if (v.ID() == Ident) { - EraseVehicle(v); - break; - } - } -} - -void TClient::EraseVehicle(TVehicleData& VehicleData) { std::unique_lock lock(mVehicleDataMutex); auto iter = std::find_if(mVehicleData.begin(), mVehicleData.end(), [&](auto& elem) { - return VehicleData.ID() == elem.ID(); + return Ident == elem.ID(); }); if (iter != mVehicleData.end()) { mVehicleData.erase(iter); } else { - debug("tried to erase a vehicle that doesn't exist!"); + debug("tried to erase a vehicle that doesn't exist (not an error)"); } }