MINOR: arg: Use chunk_destroy() to release string arguments
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.
diff --git a/src/acl.c b/src/acl.c
index 014269e..5dc77a0 100644
--- a/src/acl.c
+++ b/src/acl.c
@@ -109,9 +109,7 @@
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;
}
diff --git a/src/hlua.c b/src/hlua.c
index d2590d5..6ec69e4 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -1628,7 +1628,7 @@
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));
}
diff --git a/src/http_htx.c b/src/http_htx.c
index fb6c70a..41211bb 100644
--- a/src/http_htx.c
+++ b/src/http_htx.c
@@ -2618,17 +2618,17 @@
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 @@
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;
}
diff --git a/src/map.c b/src/map.c
index 5289e45..8cfbbe5 100644
--- a/src/map.c
+++ b/src/map.c
@@ -151,7 +151,7 @@
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 @@
}
/* 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;
diff --git a/src/payload.c b/src/payload.c
index a977233..52be784 100644
--- a/src/payload.c
+++ b/src/payload.c
@@ -1112,7 +1112,7 @@
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 @@
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;
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index ae09aea..091772d 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -1502,12 +1502,12 @@
{
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 @@
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;
}
diff --git a/src/sample.c b/src/sample.c
index 9026b6e..3a15348 100644
--- a/src/sample.c
+++ b/src/sample.c
@@ -1177,8 +1177,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
{
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 @@
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 @@
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 {