MINOR: samples: Don't allocate memory for SMP_T_METH sample when method is known
For known methods (GET,POST...), in samples, an enum is used instead of a chunk
to reference the method. So there is no needs to allocate memory when a variable
is stored with this kind of sample.
diff --git a/src/vars.c b/src/vars.c
index e5448e5..8cc0839 100644
--- a/src/vars.c
+++ b/src/vars.c
@@ -95,7 +95,7 @@
free(var->data.u.str.str);
size += var->data.u.str.len;
}
- else if (var->data.type == SMP_T_METH) {
+ else if (var->data.type == SMP_T_METH && var->data.u.meth.meth == HTTP_METH_OTHER) {
free(var->data.u.meth.str.str);
size += var->data.u.meth.str.len;
}
@@ -309,7 +309,7 @@
free(var->data.u.str.str);
var_accounting_diff(vars, smp->sess, smp->strm, -var->data.u.str.len);
}
- else if (var->data.type == SMP_T_METH) {
+ else if (var->data.type == SMP_T_METH && var->data.u.meth.meth == HTTP_METH_OTHER) {
free(var->data.u.meth.str.str);
var_accounting_diff(vars, smp->sess, smp->strm, -var->data.u.meth.str.len);
}
@@ -358,6 +358,10 @@
memcpy(var->data.u.str.str, smp->data.u.str.str, var->data.u.str.len);
break;
case SMP_T_METH:
+ var->data.u.meth.meth = smp->data.u.meth.meth;
+ if (smp->data.u.meth.meth != HTTP_METH_OTHER)
+ break;
+
if (!var_accounting_add(vars, smp->sess, smp->strm, smp->data.u.meth.str.len)) {
var->data.type = SMP_T_BOOL; /* This type doesn't use additional memory. */
return 0;
@@ -368,7 +372,6 @@
var->data.type = SMP_T_BOOL; /* This type doesn't use additional memory. */
return 0;
}
- var->data.u.meth.meth = smp->data.u.meth.meth;
var->data.u.meth.str.len = smp->data.u.meth.str.len;
var->data.u.meth.str.size = smp->data.u.meth.str.len;
memcpy(var->data.u.meth.str.str, smp->data.u.meth.str.str, var->data.u.meth.str.len);