]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: lua: ensure the memory allocator is used all the time
authorWilly Tarreau <w@1wt.eu>
Wed, 12 Apr 2017 19:40:29 +0000 (21:40 +0200)
committerWilly Tarreau <w@1wt.eu>
Thu, 13 Apr 2017 15:10:15 +0000 (17:10 +0200)
luaL_setstate() uses malloc() to initialize the first objects, and only
after this we replace the allocator. This creates trouble when replacing
the standard memory allocators during debugging sessions since the new
allocator is used to realloc() an area previously allocated using the
default malloc().

Lua provides lua_newstate() in addition to luaL_newstate(), which takes
an allocator for the initial malloc. This is exactly what we need, and
this patch does this and fixes the problem. The now useless call to
lua_setallocf() could be removed.

This has no impact outside of debugging sessions and there's no need to
backport this.

src/hlua.c

index 5383fe9a49b810d1c46d1f59d7e66e3576f7c212..77e5a9d5cf6b5ce5b4e0fa714c2142acf3a3da8c 100644 (file)
@@ -7182,7 +7182,7 @@ void hlua_init(void)
        gL.Mref = LUA_REFNIL;
        gL.flags = 0;
        LIST_INIT(&gL.com);
-       gL.T = luaL_newstate();
+       gL.T = lua_newstate(hlua_alloc, &hlua_global_allocator);
        hlua_sethlua(&gL);
        gL.Tref = LUA_REFNIL;
        gL.task = NULL;
@@ -7192,9 +7192,6 @@ void hlua_init(void)
         * process of HAProxy, this abort() is tolerated.
         */
 
-       /* change the memory allocators to track memory usage */
-       lua_setallocf(gL.T, hlua_alloc, &hlua_global_allocator);
-
        /* Initialise lua. */
        luaL_openlibs(gL.T);