diff options
author | Ferenc Wágner <wferi@niif.hu> | 2014-10-10 11:25:19 +0200 |
---|---|---|
committer | Ferenc Wágner <wferi@niif.hu> | 2014-10-12 10:13:14 +0200 |
commit | 32fb30f8bcd6f44f4301108de707a3daa32d1fca (patch) | |
tree | 645d1612097c196031c9558976308bd400240305 /com32 | |
parent | 428d9a5bd15844c072044857c8ef78b873c9ee58 (diff) | |
download | syslinux-32fb30f8bcd6f44f4301108de707a3daa32d1fca.tar.gz |
lua: garbage collect file objects
Signed-off-by: Ferenc Wágner <wferi@niif.hu>
Diffstat (limited to 'com32')
-rw-r--r-- | com32/lua/src/syslinux.c | 15 |
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); |