From 7628c635bd8f3ef486cbd06707da1926888fa9ab Mon Sep 17 00:00:00 2001 From: ThePhD Date: Mon, 5 Dec 2016 12:03:15 -0500 Subject: [PATCH] Memory leak fix! --- single/sol/sol.hpp | 13 +++++++++---- sol/reference.hpp | 9 +++++++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/single/sol/sol.hpp b/single/sol/sol.hpp index 8b0326453..426f290b1 100644 --- a/single/sol/sol.hpp +++ b/single/sol/sol.hpp @@ -20,8 +20,8 @@ // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // This file was generated with a script. -// Generated 2016-12-03 12:32:47.121440 UTC -// This header was generated with sol v2.15.3 (revision 20b951d) +// Generated 2016-12-05 17:03:03.298778 UTC +// This header was generated with sol v2.15.3 (revision 9c2c27f) // https://github.com/ThePhD/sol2 #ifndef SOL_SINGLE_INCLUDE_HPP @@ -3857,6 +3857,10 @@ namespace sol { return -1; } + void deref() const noexcept { + luaL_unref(lua_state(), LUA_REGISTRYINDEX, ref); + } + public: reference() noexcept = default; reference(lua_nil_t) noexcept : reference() {} @@ -3867,8 +3871,8 @@ namespace sol { ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX); } - virtual ~reference() noexcept { - luaL_unref(lua_state(), LUA_REGISTRYINDEX, ref); + ~reference() noexcept { + deref(); } reference(reference&& o) noexcept { @@ -3896,6 +3900,7 @@ namespace sol { reference& operator=(const reference& o) noexcept { luastate = o.luastate; + deref(); ref = o.copy(); return *this; } diff --git a/sol/reference.hpp b/sol/reference.hpp index e6bd53d99..0ee83fb5f 100644 --- a/sol/reference.hpp +++ b/sol/reference.hpp @@ -85,6 +85,10 @@ namespace sol { return -1; } + void deref() const noexcept { + luaL_unref(lua_state(), LUA_REGISTRYINDEX, ref); + } + public: reference() noexcept = default; reference(lua_nil_t) noexcept : reference() {} @@ -95,8 +99,8 @@ namespace sol { ref = luaL_ref(lua_state(), LUA_REGISTRYINDEX); } - virtual ~reference() noexcept { - luaL_unref(lua_state(), LUA_REGISTRYINDEX, ref); + ~reference() noexcept { + deref(); } reference(reference&& o) noexcept { @@ -124,6 +128,7 @@ namespace sol { reference& operator=(const reference& o) noexcept { luastate = o.luastate; + deref(); ref = o.copy(); return *this; }