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.
This commit is contained in:
Willy Tarreau 2021-07-16 10:26:56 +02:00
parent c15221b80c
commit ee0d727989

View File

@ -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. * returns true or false. It can be adjust the types if there compatibles.
* *
* This function assumes that the argp argument contains ARGM_NBARGS + 1 * 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, __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp,
uint64_t mask, struct proxy *p) uint64_t mask, struct proxy *p)
{ {
int min_arg; int min_arg;
int i, idx; int idx;
struct proxy *px; struct proxy *px;
struct userlist *ul; struct userlist *ul;
struct my_regex *reg; struct my_regex *reg;
@ -683,12 +683,6 @@ __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp,
while (1) { while (1) {
struct buffer tmp = BUF_NULL; 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. */ /* Check for mandatory arguments. */
if (argp[idx].type == ARGT_STOP) { if (argp[idx].type == ARGT_STOP) {
if (idx < min_arg) { if (idx < min_arg) {
@ -966,12 +960,7 @@ __LJMP int hlua_lua2arg_check(lua_State *L, int first, struct arg *argp,
return 0; return 0;
error: error:
for (i = 0; i < idx; i++) { free_args(argp);
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);
}
WILL_LJMP(luaL_argerror(L, first + idx, msg)); WILL_LJMP(luaL_argerror(L, first + idx, msg));
return 0; /* Never reached */ return 0; /* Never reached */
} }
@ -3529,21 +3518,11 @@ __LJMP static int hlua_run_sample_fetch(lua_State *L)
hlua_smp2lua(L, &smp); hlua_smp2lua(L, &smp);
end: end:
for (i = 0; args[i].type != ARGT_STOP; i++) { free_args(args);
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);
}
return 1; return 1;
error: error:
for (i = 0; args[i].type != ARGT_STOP; i++) { free_args(args);
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);
}
WILL_LJMP(lua_error(L)); WILL_LJMP(lua_error(L));
return 0; /* Never reached */ return 0; /* Never reached */
} }
@ -3669,21 +3648,11 @@ __LJMP static int hlua_run_sample_conv(lua_State *L)
else else
hlua_smp2lua(L, &smp); hlua_smp2lua(L, &smp);
end: end:
for (i = 0; args[i].type != ARGT_STOP; i++) { free_args(args);
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);
}
return 1; return 1;
error: error:
for (i = 0; args[i].type != ARGT_STOP; i++) { free_args(args);
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);
}
WILL_LJMP(lua_error(L)); WILL_LJMP(lua_error(L));
return 0; /* Never reached */ return 0; /* Never reached */
} }