]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
CLEANUP: hlua: use free_args() to release args arrays
authorWilly Tarreau <w@1wt.eu>
Fri, 16 Jul 2021 08:26:56 +0000 (10:26 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 16 Jul 2021 17:18:41 +0000 (19:18 +0200)
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.

src/hlua.c

index f7100465bacb0c09328c94b0acce0d83ba0ce599..f8657c502ff59afee25db02fe6b30e2220006041 100644 (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.
  *
  * 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 */
 }