Avoid removing random values from the Lua registry using Events:off()

Fix proposed in:
https://github.com/aseprite/aseprite/pull/2980#issuecomment-938495522
This commit is contained in:
David Capello 2021-10-08 11:09:47 -03:00
parent 2ddbbf00d6
commit 318d5ed6a0

View File

@ -289,7 +289,10 @@ int Events_off(lua_State* L)
return luaL_error(L, "first argument must be a function or a EventListener");
}
if (callbackRef != LUA_REFNIL) {
if (callbackRef != LUA_REFNIL &&
// Check that we are removing a listener from this Events and no
// other random value from the Lua registry
evs->hasListener(callbackRef)) {
evs->remove(callbackRef);
luaL_unref(L, LUA_REGISTRYINDEX, callbackRef);
}