[syslinux:master] lua: do not leak initramfs data chunks on garbage collection

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


Commit-ID:  6100996c0a73ee03daa44d537d799a2f2cfa501e
Gitweb:     http://www.syslinux.org/commit/6100996c0a73ee03daa44d537d799a2f2cfa501e
Author:     Ferenc Wágner <wferi at niif.hu>
AuthorDate: Sat, 11 Oct 2014 19:31:15 +0200
Committer:  Ferenc Wágner <wferi at niif.hu>
CommitDate: Mon, 13 Oct 2014 10:45:19 +0200

lua: do not leak initramfs data chunks on garbage collection

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

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

diff --git a/com32/lua/src/syslinux.c b/com32/lua/src/syslinux.c
index a23eb2f..09373a0 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},


More information about the Syslinux-commits mailing list