From edd7a82be8086ed55c45e97e239fd3bf7f2a7ad1 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Mon, 4 Jul 2016 14:09:07 +0000 Subject: [PATCH] Lunatic: fix map-text loading. The file descriptor was closed from Lua code, causing the subsequent kfilelength() to fail and attempt an allocation of (size_t)-1 bytes. git-svn-id: https://svn.eduke32.com/eduke32@5809 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/lunatic/defs.ilua | 4 +++- polymer/eduke32/source/lunatic/defs_common.lua | 6 +----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 6e31e5f43..ea90ec92a 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -1705,7 +1705,9 @@ local function readintostr_mod(fn) return nil end - return defs_c.readintostr(fd) + local ret = defs_c.readintostr(fd) + ffiC.kclose(fd) + return ret end diff --git a/polymer/eduke32/source/lunatic/defs_common.lua b/polymer/eduke32/source/lunatic/defs_common.lua index 6f608af2d..572035a0e 100644 --- a/polymer/eduke32/source/lunatic/defs_common.lua +++ b/polymer/eduke32/source/lunatic/defs_common.lua @@ -399,26 +399,22 @@ int32_t sectorofwall_noquick(int16_t theline); ]] -- Reads the whole file given by the k* file descriptor into a Lua string. --- Always closes the file descriptor. +-- Does not close the file descriptor. function readintostr(fd, kopen4load_func) -- XXX: this is pretty much the same as the code in L_RunOnce() local sz = ffiC.kfilelength(fd) if (sz == 0) then - ffiC.kclose(fd) return "" end if (sz < 0) then - ffi.kclose(fd) error("INTERNAL ERROR: kfilelength() returned negative length") end local str = ffi.new("char [?]", sz) local readlen = ffiC.kread(fd, str, sz) - ffiC.kclose(fd); fd=-1 - if (readlen ~= sz) then error("INTERNAL ERROR: couldn't read file wholly") end