aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerenc Wágner <wferi@niif.hu>2014-10-10 11:25:19 +0200
committerFerenc Wágner <wferi@niif.hu>2014-10-12 10:13:14 +0200
commit32fb30f8bcd6f44f4301108de707a3daa32d1fca (patch)
tree645d1612097c196031c9558976308bd400240305
parent428d9a5bd15844c072044857c8ef78b873c9ee58 (diff)
downloadsyslinux-32fb30f8bcd6f44f4301108de707a3daa32d1fca.tar.gz
syslinux-32fb30f8bcd6f44f4301108de707a3daa32d1fca.tar.xz
syslinux-32fb30f8bcd6f44f4301108de707a3daa32d1fca.zip
lua: garbage collect file objects
Signed-off-by: Ferenc Wágner <wferi@niif.hu>
-rw-r--r--com32/lua/src/syslinux.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/com32/lua/src/syslinux.c b/com32/lua/src/syslinux.c
index 97131095..22fd0dff 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);