lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


This seems like a really basic question - I'm probably missing some documentation or discussionsomewhere. If so, please point me at it as I couldn't find anything on this specific issue:

If I install a custom allocator as follow:

    lua_State* state = luaL_newstate();
    lua_setallocf(state, &CustomAllocator::lua_Alloc, &alloc);
    lua_close(state);

...I get zero allocations (expected, as I do no work before destroying the state) but I get several deallocations from allocations performed in luaL_newstate. This isn't safe given a custom allocator that stores a header/footer for allocations, etc as it will cause memory corruption or memory leaks.

What is the correct way of handling this? I could restore the default allocator before calling lua_closestate it seems like that would still have the same ambiguity issues (ie allocations performed with the custom allocator could be freed to the default lua allocator).

Thank you!