Skip to content

Commit

Permalink
Now without memory leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
maximegmd committed Feb 15, 2021
1 parent 9d2ffda commit 41b8f52
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/scripting/Scripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 41b8f52

Please sign in to comment.