Skip to content

Commit fa2ac40

Browse files
committed
fix(commands): Early Free (@pablo)
1 parent d13daac commit fa2ac40

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/plugins/core/scripting/server/commands.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,17 @@ void PluginCommands::RegisterCommand(std::string commandName, EValue callback)
5959
if (!callback.isFunction())
6060
return;
6161

62-
RegisterCmd(commandName, new EValue(callback));
62+
auto v = new EValue(callback);
63+
if (v->m_ref == callback.m_ref && callback.getContext()->GetKind() == ContextKinds::Lua) callback.MarkNoFree();
64+
RegisterCmd(commandName, v);
6365
}
6466

6567
std::vector<std::string> PluginCommands::GetAllCommands()
6668
{
6769
std::vector<std::string> cmdsList;
6870

6971
auto cmds = g_commandsManager->GetCommands();
70-
for(auto it = cmds.begin(); it != cmds.end(); ++it)
72+
for (auto it = cmds.begin(); it != cmds.end(); ++it)
7173
cmdsList.push_back(it->first);
7274

7375
return cmdsList;

vendor/embedder

0 commit comments

Comments
 (0)