[syslinux:master] lua: garbage collect file objects

syslinux-bot for Ferenc Wágner wferi at niif.hu
Sat Feb 14 11:09:21 PST 2015


Commit-ID:  32fb30f8bcd6f44f4301108de707a3daa32d1fca
Gitweb:     http://www.syslinux.org/commit/32fb30f8bcd6f44f4301108de707a3daa32d1fca
Author:     Ferenc Wágner <wferi at niif.hu>
AuthorDate: Fri, 10 Oct 2014 11:25:19 +0200
Committer:  Ferenc Wágner <wferi at niif.hu>
CommitDate: Sun, 12 Oct 2014 10:13:14 +0200

lua: garbage collect file objects

Signed-off-by: Ferenc Wágner <wferi at niif.hu>

---
 com32/lua/src/syslinux.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/com32/lua/src/syslinux.c b/com32/lua/src/syslinux.c
index 9713109..22fd0df 100644
--- a/com32/lua/src/syslinux.c
+++ b/com32/lua/src/syslinux.c
@@ -256,6 +256,15 @@ static int sl_loadfile(lua_State * L)
     return 1;
 }
 
+static int sl_unloadfile (lua_State *L)
+{
+    syslinux_file *file = luaL_checkudata (L, 1, SYSLINUX_FILE);
+
+    free (file->name);
+    free (file->data);
+    return 0;
+}
+
 static int sl_filesize(lua_State * L)
 {
     const syslinux_file *file = luaL_checkudata(L, 1, SYSLINUX_FILE);
@@ -430,12 +439,18 @@ static const luaL_Reg syslinuxlib[] = {
     {NULL, NULL}
 };
 
+static const luaL_Reg file_methods[] = {
+    {"__gc", sl_unloadfile},
+    {NULL, NULL}
+};
+
 /* This defines a function that opens up your library. */
 
 LUALIB_API int luaopen_syslinux(lua_State * L)
 {
 
     luaL_newmetatable(L, SYSLINUX_FILE);
+    luaL_setfuncs (L, file_methods, 0);
 
     luaL_newlib(L, syslinuxlib);
 


More information about the Syslinux-commits mailing list