From 514abd5b822135d9444a40c3dae42d43a9bcb906 Mon Sep 17 00:00:00 2001 From: kyren Date: Fri, 9 Feb 2018 07:27:12 -0500 Subject: [PATCH] Actually unref scope created types from the registry AS WELL AS destructing them --- src/lua.rs | 3 +++ src/tests.rs | 1 + 2 files changed, 4 insertions(+) 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);