From 42ef75fb849daeda001aa6b7ad01d66091ef553a Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 12 Apr 2017 21:40:29 +0200 Subject: [PATCH] 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. --- src/hlua.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/hlua.c b/src/hlua.c index 5383fe9a4..77e5a9d5c 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);