From: Willy Tarreau Date: Fri, 16 Jul 2021 08:26:56 +0000 (+0200) Subject: CLEANUP: hlua: use free_args() to release args arrays X-Git-Tag: v2.5-dev2~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee0d7279897d94894f2e149bf02d7ea18465362c;p=thirdparty%2Fhaproxy.git CLEANUP: hlua: use free_args() to release args arrays Argument arrays used in hlua_lua2arg_check() as well as in the functions used to call sample fetches and converters were manually released, let's use the cleaner and more reliable free_args() instead. The prototype of hlua_lua2arg_check() was amended to mention that the function relies on the final ARGT_STOP, which is already the case, and the pointless test for this was removed. --- diff --git a/src/hlua.c b/src/hlua.c index f7100465ba..f8657c502f 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -663,13 +663,13 @@ static int hlua_lua2smp(lua_State *L, int ud, struct sample *smp) * returns true or false. It can be adjust the types if there compatibles. * * This function assumes that the argp argument contains ARGM_NBARGS + 1 - * entries. + * entries and that there is at least one stop at the last position. */ __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp, uint64_t mask, struct proxy *p) { int min_arg; - int i, idx; + int idx; struct proxy *px; struct userlist *ul; struct my_regex *reg; @@ -683,12 +683,6 @@ __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp, while (1) { struct buffer tmp = BUF_NULL; - /* Check oversize. */ - if (idx >= ARGM_NBARGS && argp[idx].type != ARGT_STOP) { - msg = "Malformed argument mask"; - goto error; - } - /* Check for mandatory arguments. */ if (argp[idx].type == ARGT_STOP) { if (idx < min_arg) { @@ -966,12 +960,7 @@ __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp, return 0; error: - for (i = 0; i < idx; i++) { - if (argp[i].type == ARGT_STR) - chunk_destroy(&argp[i].data.str); - else if (argp[i].type == ARGT_REG) - regex_free(argp[i].data.reg); - } + free_args(argp); WILL_LJMP(luaL_argerror(L, first + idx, msg)); return 0; /* Never reached */ } @@ -3529,21 +3518,11 @@ __LJMP static int hlua_run_sample_fetch(lua_State *L) hlua_smp2lua(L, &smp); end: - for (i = 0; args[i].type != ARGT_STOP; i++) { - if (args[i].type == ARGT_STR) - chunk_destroy(&args[i].data.str); - else if (args[i].type == ARGT_REG) - regex_free(args[i].data.reg); - } + free_args(args); return 1; error: - for (i = 0; args[i].type != ARGT_STOP; i++) { - if (args[i].type == ARGT_STR) - chunk_destroy(&args[i].data.str); - else if (args[i].type == ARGT_REG) - regex_free(args[i].data.reg); - } + free_args(args); WILL_LJMP(lua_error(L)); return 0; /* Never reached */ } @@ -3669,21 +3648,11 @@ __LJMP static int hlua_run_sample_conv(lua_State *L) else hlua_smp2lua(L, &smp); end: - for (i = 0; args[i].type != ARGT_STOP; i++) { - if (args[i].type == ARGT_STR) - chunk_destroy(&args[i].data.str); - else if (args[i].type == ARGT_REG) - regex_free(args[i].data.reg); - } + free_args(args); return 1; error: - for (i = 0; args[i].type != ARGT_STOP; i++) { - if (args[i].type == ARGT_STR) - chunk_destroy(&args[i].data.str); - else if (args[i].type == ARGT_REG) - regex_free(args[i].data.reg); - } + free_args(args); WILL_LJMP(lua_error(L)); return 0; /* Never reached */ }