From 64efbfeae376af0d6b2f2ef8ebc18084eaa2b3c9 Mon Sep 17 00:00:00 2001 From: Yves Date: Sat, 26 Jul 2014 23:09:24 +0000 Subject: [PATCH] Fixes small memory leak introduced in 28bdd8540f. Thanks to leper for pointing it out. This was SVN commit r15569. --- source/graphics/MapGenerator.cpp | 10 +++++++--- source/ps/GameSetup/GameSetup.cpp | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/source/graphics/MapGenerator.cpp b/source/graphics/MapGenerator.cpp index c0bb91f072..86fa603167 100644 --- a/source/graphics/MapGenerator.cpp +++ b/source/graphics/MapGenerator.cpp @@ -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 (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; } diff --git a/source/ps/GameSetup/GameSetup.cpp b/source/ps/GameSetup/GameSetup.cpp index 71ac350c32..c1e6960018 100644 --- a/source/ps/GameSetup/GameSetup.cpp +++ b/source/ps/GameSetup/GameSetup.cpp @@ -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;