Skip to content

Commit

Permalink
Memory leak fix!
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhD committed Dec 5, 2016
1 parent 9c2c27f commit 7628c63
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
13 changes: 9 additions & 4 deletions single/sol/sol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {}
Expand All @@ -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 {
Expand Down Expand Up @@ -3896,6 +3900,7 @@ namespace sol {

reference& operator=(const reference& o) noexcept {
luastate = o.luastate;
deref();
ref = o.copy();
return *this;
}
Expand Down
9 changes: 7 additions & 2 deletions sol/reference.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand All @@ -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 {
Expand Down Expand Up @@ -124,6 +128,7 @@ namespace sol {

reference& operator=(const reference& o) noexcept {
luastate = o.luastate;
deref();
ref = o.copy();
return *this;
}
Expand Down

0 comments on commit 7628c63

Please sign in to comment.