> On 12 Apr 2017, at 23:30, Willy Tarreau <[email protected]> wrote: > > Thierry, > > while instrumenting my malloc/free functions to debug a problem, I was > hit by a malloc/realloc inconsistency in the Lua allocator. The problem > is that luaL_newstate() uses malloc() to create its first objects and > only after this one we change the allocator to use ours. Thus on the > first realloc() call it fails because it tries to reallocate using one > function something allocated differently earlier. > > I found some info regarding the fact that instead it was possible to > use lua_newstate() and pass it the allocator to use. So that's what I > did and it solve the problem for me. > > I think that it results in more accurately accounting the memory in use > by the Lua stack since even the very first malloc is counted now. But > could you take a quick look to ensure I didn't overlook anything ? I'm > attaching the patch, if you're fine with it I can merge it.
Hi, Good catch. I read the code of the Lua function luaL_newstate, and I approve your change because this function dos exactly the same job, but with a libc memory allocator. Note that a few lines after after your patch (about 15 lines), I call the function “lua_setallocf()” which set again the memory allocator. I think that this line becomes useless and it will be better to remove it. Thierry > Thanks, > Willy > <0001-MINOR-lua-ensure-the-memory-allocator-is-used-all-th.patch>

