Don't leak userdata if the metatable creation errors or panics

This commit is contained in:
kyren 2018-09-04 03:38:22 -04:00
parent 89b9968920
commit 37165a8201
1 changed files with 2 additions and 2 deletions

View File

@ -970,14 +970,14 @@ impl Lua {
let _sg = StackGuard::new(self.state);
assert_stack(self.state, 4);
let ud_index = self.userdata_metatable::<T>()?;
push_userdata::<RefCell<T>>(self.state, RefCell::new(data))?;
ffi::lua_rawgeti(
self.state,
ffi::LUA_REGISTRYINDEX,
self.userdata_metatable::<T>()? as ffi::lua_Integer,
ud_index as ffi::lua_Integer,
);
ffi::lua_setmetatable(self.state, -2);
Ok(AnyUserData(self.pop_ref()))