MINOR: stick-tables: Make static_table_key a struct variable instead of a pointer
First, this variable does not need to be publicly exposed because it is only
used by stick_table functions. So we declare it as a global static in
stick_table.c file. Then, it is useless to use a pointer. Using a plain struct
variable avoids any dynamic allocation.
diff --git a/include/proto/stick_table.h b/include/proto/stick_table.h
index a5fd400..f48b9eb 100644
--- a/include/proto/stick_table.h
+++ b/include/proto/stick_table.h
@@ -31,8 +31,6 @@
#define stktable_data_size(type) (sizeof(((union stktable_data*)0)->type))
#define stktable_data_cast(ptr, type) ((union stktable_data*)(ptr))->type
-extern struct stktable_key *static_table_key;
-
struct stksess *stksess_new(struct stktable *t, struct stktable_key *key);
void stksess_setkey(struct stktable *t, struct stksess *ts, struct stktable_key *key);
void stksess_free(struct stktable *t, struct stksess *ts);
diff --git a/src/haproxy.c b/src/haproxy.c
index 75afd97..27d4417 100644
--- a/src/haproxy.c
+++ b/src/haproxy.c
@@ -1719,7 +1719,6 @@
}
get_http_auth_buff = calloc(1, global.tune.bufsize);
- static_table_key = calloc(1, sizeof(*static_table_key));
fdinfo = calloc(1, sizeof(struct fdinfo) * (global.maxsock));
fdtab = calloc(1, sizeof(struct fdtab) * (global.maxsock));
@@ -2123,7 +2122,6 @@
free(fdinfo); fdinfo = NULL;
free(fdtab); fdtab = NULL;
free(oldpids); oldpids = NULL;
- free(static_table_key); static_table_key = NULL;
free(get_http_auth_buff); get_http_auth_buff = NULL;
free(global_listener_queue_task); global_listener_queue_task = NULL;
diff --git a/src/stick_table.c b/src/stick_table.c
index a00f1b6..0be95fe 100644
--- a/src/stick_table.c
+++ b/src/stick_table.c
@@ -41,7 +41,7 @@
#include <proto/tcp_rules.h>
/* structure used to return a table key built from a sample */
-struct stktable_key *static_table_key;
+static struct stktable_key static_table_key;
/*
* Free an allocated sticky session <ts>, and decrease sticky sessions counter
@@ -510,13 +510,13 @@
switch (t->type) {
case SMP_T_IPV4:
- static_table_key->key = &smp->data.u.ipv4;
- static_table_key->key_len = 4;
+ static_table_key.key = &smp->data.u.ipv4;
+ static_table_key.key_len = 4;
break;
case SMP_T_IPV6:
- static_table_key->key = &smp->data.u.ipv6;
- static_table_key->key_len = 16;
+ static_table_key.key = &smp->data.u.ipv6;
+ static_table_key.key_len = 16;
break;
case SMP_T_SINT:
@@ -524,15 +524,15 @@
* signed 64 it, so we can convert it inplace.
*/
*(unsigned int *)&smp->data.u.sint = (unsigned int)smp->data.u.sint;
- static_table_key->key = &smp->data.u.sint;
- static_table_key->key_len = 4;
+ static_table_key.key = &smp->data.u.sint;
+ static_table_key.key_len = 4;
break;
case SMP_T_STR:
if (!smp_make_safe(smp))
return NULL;
- static_table_key->key = smp->data.u.str.str;
- static_table_key->key_len = smp->data.u.str.len;
+ static_table_key.key = smp->data.u.str.str;
+ static_table_key.key_len = smp->data.u.str.len;
break;
case SMP_T_BIN:
@@ -550,15 +550,15 @@
t->key_size - smp->data.u.str.len);
smp->data.u.str.len = t->key_size;
}
- static_table_key->key = smp->data.u.str.str;
- static_table_key->key_len = smp->data.u.str.len;
+ static_table_key.key = smp->data.u.str.str;
+ static_table_key.key_len = smp->data.u.str.len;
break;
default: /* impossible case. */
return NULL;
}
- return static_table_key;
+ return &static_table_key;
}
/*
@@ -2362,11 +2362,11 @@
switch (px->table.type) {
case SMP_T_IPV4:
uint32_key = htonl(inetaddr_host(args[4]));
- static_table_key->key = &uint32_key;
+ static_table_key.key = &uint32_key;
break;
case SMP_T_IPV6:
inet_pton(AF_INET6, args[4], ip6_key);
- static_table_key->key = &ip6_key;
+ static_table_key.key = &ip6_key;
break;
case SMP_T_SINT:
{
@@ -2382,13 +2382,13 @@
return 1;
}
uint32_key = (uint32_t) val;
- static_table_key->key = &uint32_key;
+ static_table_key.key = &uint32_key;
break;
}
break;
case SMP_T_STR:
- static_table_key->key = args[4];
- static_table_key->key_len = strlen(args[4]);
+ static_table_key.key = args[4];
+ static_table_key.key_len = strlen(args[4]);
break;
default:
switch (appctx->ctx.table.action) {
@@ -2413,7 +2413,7 @@
if (!cli_has_level(appctx, ACCESS_LVL_OPER))
return 1;
- ts = stktable_lookup_key(&px->table, static_table_key);
+ ts = stktable_lookup_key(&px->table, &static_table_key);
switch (appctx->ctx.table.action) {
case STK_CLI_ACT_SHOW:
@@ -2442,7 +2442,7 @@
if (ts)
stktable_touch(&px->table, ts, 1);
else {
- ts = stksess_new(&px->table, static_table_key);
+ ts = stksess_new(&px->table, &static_table_key);
if (!ts) {
/* don't delete an entry which is currently referenced */
appctx->ctx.cli.msg = "Unable to allocate a new entry\n";