[Bug Fix] Fix stack leaks in Lua events #2254

EventItem was leaving the package table on the stack in successful
(non-encounter) calls and only popping the return. All events were
also leaking the full stack on lua_pcall errors. Lua mod callbacks
were popping error returns but leaking the table.
This commit is contained in:
hg authored and GitHub committed 2022-06-09 17:20:35 -05:00
1 parent bec28769aa
commit 8ef3e87370
2 files changed
+15 -9

No files matched your search

+6
View File
@@ -340,6 +340,7 @@ int LuaParser::_EventNPC(std::string package_name, QuestEventID evt, NPC* npc, M
std::string error = lua_tostring(L, -1);
AddError(error);
quest_manager.EndQuest();
lua_pop(L, npop);
return 0;
}
quest_manager.EndQuest();
@@ -433,6 +434,7 @@ int LuaParser::_EventPlayer(std::string package_name, QuestEventID evt, Client *
std::string error = lua_tostring(L, -1);
AddError(error);
quest_manager.EndQuest();
lua_pop(L, npop);
return 0;
}
quest_manager.EndQuest();
@@ -493,6 +495,7 @@ int LuaParser::_EventItem(std::string package_name, QuestEventID evt, Client *cl
} else {
lua_getfield(L, LUA_REGISTRYINDEX, package_name.c_str());
lua_getfield(L, -1, sub_name);
npop = 2;
}
lua_createtable(L, 0, 0);
@@ -516,6 +519,7 @@ int LuaParser::_EventItem(std::string package_name, QuestEventID evt, Client *cl
std::string error = lua_tostring(L, -1);
AddError(error);
quest_manager.EndQuest();
lua_pop(L, npop);
return 0;
}
quest_manager.EndQuest();
@@ -597,6 +601,7 @@ int LuaParser::_EventSpell(std::string package_name, QuestEventID evt, NPC* npc,
std::string error = lua_tostring(L, -1);
AddError(error);
quest_manager.EndQuest();
lua_pop(L, npop);
return 0;
}
quest_manager.EndQuest();
@@ -663,6 +668,7 @@ int LuaParser::_EventEncounter(std::string package_name, QuestEventID evt, std::
std::string error = lua_tostring(L, -1);
AddError(error);
quest_manager.EndQuest();
lua_pop(L, 2);
return 0;
}
quest_manager.EndQuest();