From 4d088cd620387f0b9c9b76d4e5908ab4eb27d803 Mon Sep 17 00:00:00 2001 From: momo5502 Date: Thu, 8 Jun 2017 12:22:45 +0200 Subject: [PATCH] [QuickPatch] Fix upnp memory leak --- src/Components/Modules/Console.cpp | 9 ++++----- src/Components/Modules/Dedicated.cpp | 7 ++++--- src/Components/Modules/QuickPatch.cpp | 13 +++++-------- 3 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/Components/Modules/Console.cpp b/src/Components/Modules/Console.cpp index cfd31223..6bcd451c 100644 --- a/src/Components/Modules/Console.cpp +++ b/src/Components/Modules/Console.cpp @@ -246,13 +246,12 @@ namespace Components void Console::Destroy() { - delwin(Console::OutputWindow); - delwin(Console::InputWindow); - delwin(Console::InfoWindow); - endwin(); - try { + delwin(Console::OutputWindow); + delwin(Console::InputWindow); + delwin(Console::InfoWindow); + endwin(); delscreen(SP); } catch (...) diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index e0266ee8..0f1e149f 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -397,13 +397,14 @@ namespace Components #ifdef USE_LEGACY_SERVER_LIST // Heartbeats + Scheduler::Once(Dedicated::Heartbeat); Scheduler::OnFrame([] () { - static int LastHeartbeat = 0; + static Utils::Time::Interval interval; - if (Dvar::Var("sv_maxclients").get() > 0 && !LastHeartbeat || (Game::Com_Milliseconds() - LastHeartbeat) > 120 * 1000) + if (Dvar::Var("sv_maxclients").get() > 0 && interval.elapsed(2min)) { - LastHeartbeat = Game::Com_Milliseconds(); + interval.update(); Dedicated::Heartbeat(); } }); diff --git a/src/Components/Modules/QuickPatch.cpp b/src/Components/Modules/QuickPatch.cpp index 5eb2b1ac..83c96b7b 100644 --- a/src/Components/Modules/QuickPatch.cpp +++ b/src/Components/Modules/QuickPatch.cpp @@ -260,20 +260,17 @@ namespace Components // spawn upnp thread when UPNP_init returns Utils::Hook::Hook(0x47982B, []() { - std::thread upnpThread([]() + std::thread([]() { // check natpmpstate // state 4 is no more devices to query - while (true) + while (Utils::Hook::Get(0x66CE200) < 4) { - if (Utils::Hook::Get(0x66CE200) < 4) - { - Utils::Hook::Call(0x4D7030)(); - } + Utils::Hook::Call(0x4D7030)(); std::this_thread::sleep_for(500ms); } - }); - }, HOOK_JUMP); + }).detach(); + }, HOOK_JUMP).install()->quick(); // disable the IWNet IP detection (default 'got ipdetect' flag to 1) Utils::Hook::Set(0x649D6F0, 1);