summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-04-02 21:19:54 +1100
committerjacqueline <me@jacqueline.id.au>2024-04-02 21:19:54 +1100
commit63bc8cf896bc2fbe7cda123cfe1479461f985e76 (patch)
treebb0b40542da81417acfb531cb65c52e95b3af0a1
parentc24479d4d8c2d6258615bb7778036f0fb3440703 (diff)
downloadtangara-fw-63bc8cf896bc2fbe7cda123cfe1479461f985e76.tar.gz
Ensure we always clean up after ourselves when invoking bindings
this fixes a very nasty lua stack leak
-rw-r--r--src/lua/property.cpp12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/lua/property.cpp b/src/lua/property.cpp
index 200f4d5c..e136ad90 100644
--- a/src/lua/property.cpp
+++ b/src/lua/property.cpp
@@ -379,22 +379,22 @@ auto Property::Update(const LuaValue& v) -> void {
for (int i = bindings_.size() - 1; i >= 0; i--) {
auto& b = bindings_[i];
+ int top = lua_gettop(b.first);
+
lua_pushstring(b.first, kBindingsTable);
lua_gettable(b.first, LUA_REGISTRYINDEX); // REGISTRY[kBindingsTable]
int type = lua_rawgeti(b.first, -1, b.second); // push bindings[i]
// Has closure has been GCed?
if (type == LUA_TNIL) {
- // Clean up after ourselves.
- lua_pop(b.first, 1);
// Remove the binding.
bindings_.erase(bindings_.begin() + i);
- continue;
+ } else {
+ PushValue(*b.first); // push the argument
+ CallProtected(b.first, 1, 0); // invoke the closure
}
- PushValue(*b.first); // push the argument
- CallProtected(b.first, 1, 0); // invoke the closure
- lua_pop(b.first, 1); // pop the bindings table
+ lua_settop(b.first, top); // clean up after ourselves
}
}