From 48a1ec3531ff9b884d177af147397aab3ac616a7 Mon Sep 17 00:00:00 2001 From: TheLastRar Date: Fri, 12 Jul 2024 18:21:47 +0100 Subject: [PATCH] DEV9: Use std::unique_ptr for tracking active pings --- .../DEV9/Sessions/ICMP_Session/ICMP_Session.cpp | 17 +++++------------ pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.h | 3 +-- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.cpp b/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.cpp index 78917da159..96692d4ef7 100644 --- a/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.cpp +++ b/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.cpp @@ -685,7 +685,7 @@ namespace Sessions pingRet = pings[i]->Recv(); if (pingRet != nullptr) { - Ping* ping = pings[i]; + std::unique_ptr ping = std::move(pings[i]); // Remove ping from list and unlock mutex pings.erase(pings.begin() + i); lock.unlock(); @@ -729,9 +729,6 @@ namespace Sessions else DevCon.WriteLn("DEV9: ICMP: ICMP timeout"); - // Free ping - delete ping; - if (ret.has_value()) DevCon.WriteLn("DEV9: ICMP: Return Ping"); @@ -848,13 +845,12 @@ namespace Sessions DevCon.WriteLn("DEV9: ICMP: Send Ping"); open++; - Ping* ping = new Ping(icmpPayload->GetLength()); + std::unique_ptr ping = std::make_unique(icmpPayload->GetLength()); if (!ping->IsInitialised()) { if (--open == 0) RaiseEventConnectionClosed(); - delete ping; return false; } @@ -862,7 +858,6 @@ namespace Sessions { if (--open == 0) RaiseEventConnectionClosed(); - delete ping; return false; } @@ -873,7 +868,7 @@ namespace Sessions { std::scoped_lock lock(ping_mutex); - pings.push_back(ping); + pings.push_back(std::move(ping)); } break; @@ -892,10 +887,8 @@ namespace Sessions ICMP_Session::~ICMP_Session() { - std::scoped_lock lock(ping_mutex); - // Cleanup - for (size_t i = 0; i < pings.size(); i++) - delete pings[i]; + std::scoped_lock lock(ping_mutex); + pings.clear(); } } // namespace Sessions diff --git a/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.h b/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.h index e827c3b4af..7d197903f0 100644 --- a/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.h +++ b/pcsx2/DEV9/Sessions/ICMP_Session/ICMP_Session.h @@ -68,9 +68,8 @@ namespace Sessions ~Ping(); }; - SimpleQueue _recvBuff; std::mutex ping_mutex; - std::vector pings; + std::vector> pings; ThreadSafeMap* connections; std::atomic open{0};