mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-11-30 07:11:04 +01:00
BUG/MINOR: hlua: Fix memory leaks on error path when registering a fetch
When an error occurred in hlua_register_fetches(), the allocated lua function and keyword must be released to avoid memory leaks. This patch depends on "MINOR: hlua: Add function to release a lua function". It may be backported in all stable versions. It should fix #1112.
This commit is contained in:
parent
aa22430bba
commit
2567f18382
16
src/hlua.c
16
src/hlua.c
@ -6820,7 +6820,7 @@ __LJMP static int hlua_register_fetches(lua_State *L)
|
|||||||
int ref;
|
int ref;
|
||||||
int len;
|
int len;
|
||||||
struct sample_fetch_kw_list *sfk;
|
struct sample_fetch_kw_list *sfk;
|
||||||
struct hlua_function *fcn;
|
struct hlua_function *fcn = NULL;
|
||||||
struct sample_fetch *sf;
|
struct sample_fetch *sf;
|
||||||
struct buffer *trash;
|
struct buffer *trash;
|
||||||
|
|
||||||
@ -6849,15 +6849,15 @@ __LJMP static int hlua_register_fetches(lua_State *L)
|
|||||||
/* Allocate and fill the sample fetch keyword struct. */
|
/* Allocate and fill the sample fetch keyword struct. */
|
||||||
sfk = calloc(1, sizeof(*sfk) + sizeof(struct sample_fetch) * 2);
|
sfk = calloc(1, sizeof(*sfk) + sizeof(struct sample_fetch) * 2);
|
||||||
if (!sfk)
|
if (!sfk)
|
||||||
WILL_LJMP(luaL_error(L, "Lua out of memory error."));
|
goto alloc_error;
|
||||||
fcn = new_hlua_function();
|
fcn = new_hlua_function();
|
||||||
if (!fcn)
|
if (!fcn)
|
||||||
WILL_LJMP(luaL_error(L, "Lua out of memory error."));
|
goto alloc_error;
|
||||||
|
|
||||||
/* Fill fcn. */
|
/* Fill fcn. */
|
||||||
fcn->name = strdup(name);
|
fcn->name = strdup(name);
|
||||||
if (!fcn->name)
|
if (!fcn->name)
|
||||||
WILL_LJMP(luaL_error(L, "Lua out of memory error."));
|
goto alloc_error;
|
||||||
fcn->function_ref[hlua_state_id] = ref;
|
fcn->function_ref[hlua_state_id] = ref;
|
||||||
|
|
||||||
/* List head */
|
/* List head */
|
||||||
@ -6867,7 +6867,7 @@ __LJMP static int hlua_register_fetches(lua_State *L)
|
|||||||
len = strlen("lua.") + strlen(name) + 1;
|
len = strlen("lua.") + strlen(name) + 1;
|
||||||
sfk->kw[0].kw = calloc(1, len);
|
sfk->kw[0].kw = calloc(1, len);
|
||||||
if (!sfk->kw[0].kw)
|
if (!sfk->kw[0].kw)
|
||||||
return luaL_error(L, "Lua out of memory error.");
|
goto alloc_error;
|
||||||
|
|
||||||
snprintf((char *)sfk->kw[0].kw, len, "lua.%s", name);
|
snprintf((char *)sfk->kw[0].kw, len, "lua.%s", name);
|
||||||
sfk->kw[0].process = hlua_sample_fetch_wrapper;
|
sfk->kw[0].process = hlua_sample_fetch_wrapper;
|
||||||
@ -6882,6 +6882,12 @@ __LJMP static int hlua_register_fetches(lua_State *L)
|
|||||||
sample_register_fetches(sfk);
|
sample_register_fetches(sfk);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
alloc_error:
|
||||||
|
release_hlua_function(fcn);
|
||||||
|
ha_free(&sfk);
|
||||||
|
WILL_LJMP(luaL_error(L, "Lua out of memory error."));
|
||||||
|
return 0; /* Never reached */
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function is a lua binding to set the wake_time.
|
/* This function is a lua binding to set the wake_time.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user