Re: Custom Lua allocation function's freeing throws COMException

  • From: Mars Arkane <marsarkane@xxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Mon, 13 Feb 2017 00:11:07 +0100

Another problem I just noticed is that returning a null pointer from the
allocation function, when too much memory is in use, crashes the program
with LuaJit =/ This too works fine with Lua.

2017-02-12 23:16 GMT+01:00 Mike Pall <mikelj-1702@xxxxxxx>:

Mars Arkane wrote:
[...] I simply set that function with lua_setallocf [...]

Umm ... so you're using luaL_newstate() and then later on setting
lua_setallocf? That's not a good idea.

A state created by luaL_newstate() already has some memory
allocated with the default allocator. These memory blocks will
eventually be passed to your allocator for freeing; at the latest
during lua_close(). It's most certainly not prepared to deal with
foreign memory blocks.

Because detecting foreign memory blocks is non-trivial, check out
lua_newstate() ('lua_', not 'luaL_') for a better solution.

The other restriction is that the (current default) x64 build has
special needs regarding the allocated memory areas, which your
allocator most probably doesn't fulfill. Turn on assertions when
building LuaJIT to catch this (and other issues).

--Mike


Other related posts: