[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()
{
try
{
delwin(Console::OutputWindow);
delwin(Console::InputWindow);
delwin(Console::InfoWindow);
endwin();
try
{
delscreen(SP);
}
catch (...)

View File

@ -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<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();
}
});

View File

@ -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)
{
if (Utils::Hook::Get<int>(0x66CE200) < 4)
while (Utils::Hook::Get<int>(0x66CE200) < 4)
{
Utils::Hook::Call<void()>(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<BYTE>(0x649D6F0, 1);