From 32fb30f8bcd6f44f4301108de707a3daa32d1fca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferenc=20W=C3=A1gner?= Date: Fri, 10 Oct 2014 11:25:19 +0200 Subject: lua: garbage collect file objects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ferenc Wágner --- com32/lua/src/syslinux.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'com32') 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); -- cgit v1.2.1