[QuickPatch] Fix upnp memory leak

This commit is contained in:
momo5502 2017-06-08 12:22:45 +02:00
parent cfb252b3ee
commit 4d088cd620
3 changed files with 13 additions and 16 deletions

View File

@ -245,14 +245,13 @@ namespace Components
} }
void Console::Destroy() void Console::Destroy()
{
try
{ {
delwin(Console::OutputWindow); delwin(Console::OutputWindow);
delwin(Console::InputWindow); delwin(Console::InputWindow);
delwin(Console::InfoWindow); delwin(Console::InfoWindow);
endwin(); endwin();
try
{
delscreen(SP); delscreen(SP);
} }
catch (...) catch (...)

View File

@ -397,13 +397,14 @@ namespace Components
#ifdef USE_LEGACY_SERVER_LIST #ifdef USE_LEGACY_SERVER_LIST
// Heartbeats // Heartbeats
Scheduler::Once(Dedicated::Heartbeat);
Scheduler::OnFrame([] () Scheduler::OnFrame([] ()
{ {
static int LastHeartbeat = 0; static Utils::Time::Interval interval;
if (Dvar::Var("sv_maxclients").get<int>() > 0 && !LastHeartbeat || (Game::Com_Milliseconds() - LastHeartbeat) > 120 * 1000) if (Dvar::Var("sv_maxclients").get<int>() > 0 && interval.elapsed(2min))
{ {
LastHeartbeat = Game::Com_Milliseconds(); interval.update();
Dedicated::Heartbeat(); Dedicated::Heartbeat();
} }
}); });

View File

@ -260,20 +260,17 @@ namespace Components
// spawn upnp thread when UPNP_init returns // spawn upnp thread when UPNP_init returns
Utils::Hook::Hook(0x47982B, []() Utils::Hook::Hook(0x47982B, []()
{ {
std::thread upnpThread([]() std::thread([]()
{ {
// check natpmpstate // check natpmpstate
// state 4 is no more devices to query // state 4 is no more devices to query
while (true) while (Utils::Hook::Get<int>(0x66CE200) < 4)
{
if (Utils::Hook::Get<int>(0x66CE200) < 4)
{ {
Utils::Hook::Call<void()>(0x4D7030)(); Utils::Hook::Call<void()>(0x4D7030)();
}
std::this_thread::sleep_for(500ms); std::this_thread::sleep_for(500ms);
} }
}); }).detach();
}, HOOK_JUMP); }, HOOK_JUMP).install()->quick();
// disable the IWNet IP detection (default 'got ipdetect' flag to 1) // disable the IWNet IP detection (default 'got ipdetect' flag to 1)
Utils::Hook::Set<BYTE>(0x649D6F0, 1); Utils::Hook::Set<BYTE>(0x649D6F0, 1);