From: Willy Tarreau Date: Wed, 12 Apr 2017 19:40:29 +0000 (+0200) Subject: MINOR: lua: ensure the memory allocator is used all the time X-Git-Tag: v1.8-dev2~84 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42ef75fb849daeda001aa6b7ad01d66091ef553a;p=thirdparty%2Fhaproxy.git MINOR: lua: ensure the memory allocator is used all the time 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. --- diff --git a/src/hlua.c b/src/hlua.c index 5383fe9a49..77e5a9d5cf 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -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);