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.
This commit is contained in:
Christopher Faulet 2020-08-07 11:45:18 +02:00
parent fd2e906084
commit 6ad7df423b
7 changed files with 29 additions and 39 deletions

View File

@ -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;
}

View 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));
}

View 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;
}

View File

@ -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;

View 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;

View 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;
}

View 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 {