diff --git a/src/lua.rs b/src/lua.rs index c14d364..de86ac8 100644 --- a/src/lua.rs +++ b/src/lua.rs @@ -1080,6 +1080,8 @@ impl<'lua, 'scope> Scope<'lua, 'scope> { ffi::LUA_REGISTRYINDEX, registry_id as ffi::lua_Integer, ); + ffi::luaL_unref(state, ffi::LUA_REGISTRYINDEX, registry_id); + ffi::lua_getupvalue(state, -1, 1); let ud = take_userdata::>(state); @@ -1109,6 +1111,7 @@ impl<'lua, 'scope> Scope<'lua, 'scope> { ffi::LUA_REGISTRYINDEX, registry_id as ffi::lua_Integer, ); + ffi::luaL_unref(state, ffi::LUA_REGISTRYINDEX, registry_id); Box::new(take_userdata::>(state)) })); Ok(u) diff --git a/src/tests.rs b/src/tests.rs index f8ce37a..cd661f4 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -614,6 +614,7 @@ fn scope_func() { .unwrap(); lua.globals().set("bad", f.clone()).unwrap(); f.call::<_, ()>(()).unwrap(); + assert_eq!(Rc::strong_count(&rc), 2); }); assert_eq!(rc.get(), 42); assert_eq!(Rc::strong_count(&rc), 1);