aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFerenc Wágner <wferi@niif.hu>2014-10-11 19:31:15 +0200
committerFerenc Wágner <wferi@niif.hu>2014-10-13 10:45:19 +0200
commit6100996c0a73ee03daa44d537d799a2f2cfa501e (patch)
tree9f07de8ebcc6e8a3b88a0fc7408f9a1e8e55bc84
parent73fb321a5d56bb4fe8cbb3d706c792007d30b090 (diff)
downloadsyslinux-6100996c0a73ee03daa44d537d799a2f2cfa501e.tar.gz
syslinux-6100996c0a73ee03daa44d537d799a2f2cfa501e.tar.xz
syslinux-6100996c0a73ee03daa44d537d799a2f2cfa501e.zip
lua: do not leak initramfs data chunks on garbage collection
Signed-off-by: Ferenc Wágner <wferi@niif.hu>
-rw-r--r--com32/lua/src/syslinux.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/com32/lua/src/syslinux.c b/com32/lua/src/syslinux.c
index a23eb2f0..09373a02 100644
--- a/com32/lua/src/syslinux.c
+++ b/com32/lua/src/syslinux.c
@@ -318,6 +318,21 @@ static int sl_initramfs_size (lua_State *L)
return 1;
}
+static int sl_initramfs_purge (lua_State *L)
+{
+ struct initramfs *ir = luaL_checkudata(L, 1, SYSLINUX_INITRAMFS);
+
+ ir = ir->next;
+ while (ir->len) {
+ free ((void *)ir->data);
+ ir = ir->next;
+ free (ir->prev);
+ }
+ /* the __gc method may also be (repeatedly) called before garbage collection, so: */
+ ir->next = ir->prev = ir;
+ return 0;
+}
+
static int sl_boot_it(lua_State * L)
{
const syslinux_file *kernel = luaL_checkudata(L, 1, SYSLINUX_FILE);
@@ -442,6 +457,7 @@ static const luaL_Reg file_methods[] = {
};
static const luaL_Reg initramfs_methods[] = {
+ {"__gc", sl_initramfs_purge},
{"load", sl_initramfs_load_archive},
{"add_file", sl_initramfs_add_file},
{"size", sl_initramfs_size},