]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: arg: Use chunk_destroy() to release string arguments
authorChristopher Faulet <cfaulet@haproxy.com>
Fri, 7 Aug 2020 09:45:18 +0000 (11:45 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Fri, 7 Aug 2020 12:27:54 +0000 (14:27 +0200)
This way, all fields of the buffer structure are reset when a string argument
(ARGT_STR) is released.  It is also a good way to explicitly specify this kind
of argument is a chunk. So .data and .size fields must be set.

This patch may be backported to ease backports.

src/acl.c
src/hlua.c
src/http_htx.c
src/map.c
src/payload.c
src/proto_tcp.c
src/sample.c

index 014269e74c75133b3851db8c7cf35b7aab756ed1..5dc77a0fdb4ef54a74631f726c16e428e6c82daf 100644 (file)
--- a/src/acl.c
+++ b/src/acl.c
@@ -109,9 +109,7 @@ static struct acl_expr *prune_acl_expr(struct acl_expr *expr)
                if (arg->type == ARGT_STOP)
                        break;
                if (arg->type == ARGT_STR || arg->unresolved) {
-                       free(arg->data.str.area);
-                       arg->data.str.area = NULL;
-                       arg->data.str.data = 0;
+                       chunk_destroy(&arg->data.str);
                        unresolved |= arg->unresolved;
                        arg->unresolved = 0;
                }
index d2590d59d4abb26a4495aff89baebae4677f11ed..6ec69e4cf3ea1554fbd24b37926b426908e52ea3 100644 (file)
@@ -1628,7 +1628,7 @@ __LJMP static int hlua_map_new(struct lua_State *L)
                lua_pushfstring(L, "'new': %s.", err);
                lua_concat(L, 2);
                free(err);
-               free(args[0].data.str.area);
+               chunk_destroy(&args[0].data.str);
                WILL_LJMP(lua_error(L));
        }
 
index fb6c70af857ec02c8a707a3716b7a23151c7f200..41211bb8ff01690dc4b918a7da16d6d6aa3c9960 100644 (file)
@@ -2618,17 +2618,17 @@ int val_blk_arg(struct arg *arg, char **err_msg)
                return 0;
        }
        if (arg[0].data.str.data == 4 && !strncmp(arg[0].data.str.area, "head", 4)) {
-               free(arg[0].data.str.area);
+               chunk_destroy(&arg[0].data.str);
                arg[0].type = ARGT_SINT;
                arg[0].data.sint = -1;
        }
        else if (arg[0].data.str.data == 4 && !strncmp(arg[0].data.str.area, "tail", 4)) {
-               free(arg[0].data.str.area);
+               chunk_destroy(&arg[0].data.str);
                arg[0].type = ARGT_SINT;
                arg[0].data.sint = -2;
        }
        else if (arg[0].data.str.data == 5 && !strncmp(arg[0].data.str.area, "first", 5)) {
-               free(arg[0].data.str.area);
+               chunk_destroy(&arg[0].data.str);
                arg[0].type = ARGT_SINT;
                arg[0].data.sint = -3;
        }
@@ -2647,7 +2647,7 @@ int val_blk_arg(struct arg *arg, char **err_msg)
                        memprintf(err_msg, "block position must not be negative");
                        return 0;
                }
-               free(arg[0].data.str.area);
+               chunk_destroy(&arg[0].data.str);
                arg[0].type = ARGT_SINT;
                arg[0].data.sint = pos;
        }
index 5289e458a39e585e613ec7d3416fa052f1b291b2..8cfbbe51a1381705ced603829eb376b329184429 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -151,7 +151,7 @@ int sample_load_map(struct arg *arg, struct sample_conv *conv,
                                  arg[1].data.str.area);
                        return 0;
                }
-               free(arg[1].data.str.area);
+               chunk_destroy(&arg[1].data.str);
                if (data.type == SMP_T_IPV4) {
                        arg[1].type = ARGT_IPV4;
                        arg[1].data.ipv4 = data.u.ipv4;
@@ -162,7 +162,7 @@ int sample_load_map(struct arg *arg, struct sample_conv *conv,
        }
 
        /* replace the first argument by this definition */
-       free(arg[0].data.str.area);
+       chunk_destroy(&arg[0].data.str);
        arg[0].type = ARGT_MAP;
        arg[0].data.map = desc;
 
index a977233de0d9c80973a7e7b63f48ce9fe87add6f..52be7848a3a12512e19c5ddbab2035ff90c75ecb 100644 (file)
@@ -1112,7 +1112,7 @@ int val_payload_lv(struct arg *arg, char **err_msg)
                        memprintf(err_msg, "payload offset2 is not a number");
                        return 0;
                }
-               free(arg[2].data.str.area);
+               chunk_destroy(&arg[2].data.str);
                arg[2].type = ARGT_SINT;
                arg[2].data.sint = i;
 
@@ -1314,7 +1314,7 @@ int val_distcc(struct arg *arg, char **err_msg)
        token = (arg[0].data.str.area[0] << 24) + (arg[0].data.str.area[1] << 16) +
                (arg[0].data.str.area[2] << 8) + (arg[0].data.str.area[3] << 0);
 
-       free(arg[0].data.str.area);
+       chunk_destroy(&arg[0].data.str);
        arg[0].type      = ARGT_SINT;
        arg[0].data.sint = token;
 
index ae09aea29e3810565e125999dbb5e30173f0891d..091772d40a02dd510a7ca3d193d6b334dc9966f2 100644 (file)
@@ -1502,12 +1502,12 @@ static int val_fc_time_value(struct arg *args, char **err)
 {
        if (args[0].type == ARGT_STR) {
                if (strcmp(args[0].data.str.area, "us") == 0) {
-                       free(args[0].data.str.area);
+                       chunk_destroy(&args[0].data.str);
                        args[0].type = ARGT_SINT;
                        args[0].data.sint = TIME_UNIT_US;
                }
                else if (strcmp(args[0].data.str.area, "ms") == 0) {
-                       free(args[0].data.str.area);
+                       chunk_destroy(&args[0].data.str);
                        args[0].type = ARGT_SINT;
                        args[0].data.sint = TIME_UNIT_MS;
                }
@@ -1536,7 +1536,7 @@ static int var_fc_counter(struct arg *args, char **err)
        if (args[0].type != ARGT_STOP) {
                ha_warning("no argument supported for 'fc_*' sample expressions returning counters.\n");
                if (args[0].type == ARGT_STR)
-                       free(args[0].data.str.area);
+                       chunk_destroy(&args[0].data.str);
                args[0].type = ARGT_STOP;
        }
 
index 9026b6e9c9f635ae422c232a221f0a5baae2c484..3a1534865989a3b71c7b086b87bc242121255633 100644 (file)
@@ -1177,8 +1177,7 @@ int smp_resolve_args(struct proxy *p)
                                break;
                        }
 
-                       free(arg->data.str.area);
-                       arg->data.str.area = NULL;
+                       chunk_destroy(&arg->data.str);
                        arg->unresolved = 0;
                        arg->data.srv = srv;
                        break;
@@ -1205,8 +1204,7 @@ int smp_resolve_args(struct proxy *p)
                                break;
                        }
 
-                       free(arg->data.str.area);
-                       arg->data.str.area = NULL;
+                       chunk_destroy(&arg->data.str);
                        arg->unresolved = 0;
                        arg->data.prx = px;
                        break;
@@ -1233,8 +1231,7 @@ int smp_resolve_args(struct proxy *p)
                                break;
                        }
 
-                       free(arg->data.str.area);
-                       arg->data.str.area = NULL;
+                       chunk_destroy(&arg->data.str);
                        arg->unresolved = 0;
                        arg->data.prx = px;
                        break;
@@ -1274,8 +1271,7 @@ int smp_resolve_args(struct proxy *p)
                                t->proxies_list = p;
                        }
 
-                       free(arg->data.str.area);
-                       arg->data.str.area = NULL;
+                       chunk_destroy(&arg->data.str);
                        arg->unresolved = 0;
                        arg->data.t = t;
                        break;
@@ -1304,8 +1300,7 @@ int smp_resolve_args(struct proxy *p)
                                break;
                        }
 
-                       free(arg->data.str.area);
-                       arg->data.str.area = NULL;
+                       chunk_destroy(&arg->data.str);
                        arg->unresolved = 0;
                        arg->data.usr = ul;
                        break;
@@ -1332,8 +1327,7 @@ int smp_resolve_args(struct proxy *p)
                                continue;
                        }
 
-                       free(arg->data.str.area);
-                       arg->data.str.area = NULL;
+                       chunk_destroy(&arg->data.str);
                        arg->unresolved = 0;
                        arg->data.reg = reg;
                        break;
@@ -1402,8 +1396,7 @@ static void release_sample_arg(struct arg *p)
 
        while (p->type != ARGT_STOP) {
                if (p->type == ARGT_STR || p->unresolved) {
-                       free(p->data.str.area);
-                       p->data.str.area = NULL;
+                       chunk_destroy(&p->data.str);
                        p->unresolved = 0;
                }
                else if (p->type == ARGT_REG) {
@@ -1514,7 +1507,7 @@ static int smp_check_debug(struct arg *args, struct sample_conv *conv,
                return 0;
        }
 
-       free(args[1].data.str.area);
+       chunk_destroy(&args[1].data.str);
        args[1].type = ARGT_PTR;
        args[1].data.ptr = sink;
        return 1;
@@ -2174,7 +2167,7 @@ static int sample_conv_json_check(struct arg *arg, struct sample_conv *conv,
                return 0;
        }
 
-       free(arg->data.str.area);
+       chunk_destroy(&arg->data.str);
        arg->type = ARGT_SINT;
        arg->data.sint = type;
        return 1;
@@ -2667,7 +2660,7 @@ static int check_operator(struct arg *args, struct sample_conv *conv,
                return 0;
        }
 
-       free(args[0].data.str.area);
+       chunk_destroy(&args[0].data.str);
        args[0].type = ARGT_SINT;
        args[0].data.sint = i;
        return 1;
@@ -3193,7 +3186,7 @@ static int sample_conv_protobuf_check(struct arg *args, struct sample_conv *conv
                        return 0;
                }
 
-               free(args[1].data.str.area);
+               chunk_destroy(&args[1].data.str);
                args[1].type = ARGT_SINT;
                args[1].data.sint = pbuf_type;
        }
@@ -3376,7 +3369,7 @@ int smp_check_date_unit(struct arg *args, char **err)
                         return 0;
                 }
 
-               free(args[1].data.str.area);
+               chunk_destroy(&args[1].data.str);
                 args[1].type = ARGT_SINT;
                args[1].data.sint = unit;
         }
@@ -3565,14 +3558,14 @@ static int smp_check_const_bool(struct arg *args, char **err)
 {
        if (strcasecmp(args[0].data.str.area, "true") == 0 ||
            strcasecmp(args[0].data.str.area, "1") == 0) {
-               free(args[0].data.str.area);
+               chunk_destroy(&args[0].data.str);
                args[0].type = ARGT_SINT;
                args[0].data.sint = 1;
                return 1;
        }
        if (strcasecmp(args[0].data.str.area, "false") == 0 ||
            strcasecmp(args[0].data.str.area, "0") == 0) {
-               free(args[0].data.str.area);
+               chunk_destroy(&args[0].data.str);
                args[0].type = ARGT_SINT;
                args[0].data.sint = 0;
                return 1;
@@ -3616,7 +3609,7 @@ static int smp_check_const_bin(struct arg *args, char **err)
 
        if (!parse_binary(args[0].data.str.area, &binstr, &binstrlen, err))
                return 0;
-       free(args[0].data.str.area);
+       chunk_destroy(&args[0].data.str);
        args[0].type = ARGT_STR;
        args[0].data.str.area = binstr;
        args[0].data.str.data = binstrlen;
@@ -3639,8 +3632,7 @@ static int smp_check_const_meth(struct arg *args, char **err)
 
        meth = find_http_meth(args[0].data.str.area, args[0].data.str.data);
        if (meth != HTTP_METH_OTHER) {
-               free(args[0].data.str.area);
-
+               chunk_destroy(&args[0].data.str);
                args[0].type = ARGT_SINT;
                args[0].data.sint = meth;
        } else {