From 41b8f523905290b773d39ef2dbd2df5ac55d95fb Mon Sep 17 00:00:00 2001 From: yamashi Date: Mon, 15 Feb 2021 21:05:59 +0100 Subject: [PATCH] Now without memory leaks --- src/scripting/Scripting.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/scripting/Scripting.cpp b/src/scripting/Scripting.cpp index 4b15d9ed..b7e1c273 100644 --- a/src/scripting/Scripting.cpp +++ b/src/scripting/Scripting.cpp @@ -59,19 +59,26 @@ void Scripting::HandleOverridenFunction(RED4ext::IScriptable* apContext, RED4ext // Nasty way of popping all args for (auto& pArg : apCookie->FunctionDefinition->params) { - char holder[1 << 12]; + auto* pType = pArg->type; + auto* pAllocator = pType->GetAllocator(); + + auto* pInstance = pAllocator->Alloc(pType->GetSize()).memory; + pType->Init(pInstance); RED4ext::CStackType arg; arg.type = pArg->type; - arg.value = holder; + arg.value = pInstance; apFrame->unk30 = 0; apFrame->unk38 = 0; const auto opcode = *(apFrame->code++); - GetScriptCallArray()[opcode](apFrame->context, apFrame, holder, nullptr); + GetScriptCallArray()[opcode](apFrame->context, apFrame, pInstance, nullptr); apFrame->code++; // skip ParamEnd args.push_back(ToLua(apCookie->pScripting->m_lua, arg)); + + pType->Destroy(pInstance); + pAllocator->Free(pInstance); } const auto result = apCookie->ScriptFunction(as_args(args), apCookie->Environment);