Fixes small memory leak introduced in 28bdd8540f.

Thanks to leper for pointing it out.

This was SVN commit r15569.
This commit is contained in:
Yves 2014-07-26 23:09:24 +00:00
parent 28bdd8540f
commit 64efbfeae3
2 changed files with 9 additions and 5 deletions

View File

@ -82,6 +82,13 @@ bool CMapGeneratorWorker::Run()
JSContext* cx = m_ScriptInterface->GetContext();
JSAutoRequest rq(cx);
// We must destroy the ScriptInterface in the same thread because the JSAPI requires that!
struct AutoFree {
AutoFree(ScriptInterface* p) : m_p(p) {}
~AutoFree() { SAFE_DELETE(m_p); }
ScriptInterface* m_p;
} autoFree(m_ScriptInterface);
m_ScriptInterface->SetCallbackData(static_cast<void*> (this));
// Replace RNG with a seeded deterministic function
@ -131,9 +138,6 @@ bool CMapGeneratorWorker::Run()
LOGERROR(L"CMapGeneratorWorker::Run: Failed to load RMS '%ls'", m_ScriptPath.string().c_str());
return false;
}
// We must destroy the ScriptInterface in the same thread because the JSAPI requires that!
SAFE_DELETE(m_ScriptInterface);
return true;
}

View File

@ -1207,8 +1207,8 @@ bool Autostart(const CmdLineArgs& args)
mapSize = size.ToUInt();
}
scriptInterface.SetProperty(settings, "Seed", seed); // Random seed
scriptInterface.SetProperty(settings, "Size", mapSize); // Random map size (in patches)
scriptInterface.SetProperty(settings, "Seed", seed); // Random seed
scriptInterface.SetProperty(settings, "Size", mapSize); // Random map size (in patches)
// Get optional number of players (default 2)
size_t numPlayers = 2;