From c0f64fc36ae6de7b222a22fb485ba55ada3ad98e Mon Sep 17 00:00:00 2001 From: Olivier Houchard Date: Wed, 7 Jan 2026 02:57:06 +0100 Subject: [PATCH] MINOR: receiver: Dynamically alloc the "members" field of shard_info Instead of always allocating MAX_TGROUPS members, allocate them dynamically, using the number of thread groups we'll use, so that increasing MAX_TGROUPS will not have a huge impact on the structure size. --- include/haproxy/receiver-t.h | 2 +- src/listener.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/include/haproxy/receiver-t.h b/include/haproxy/receiver-t.h index d1897de51..976cc70c7 100644 --- a/include/haproxy/receiver-t.h +++ b/include/haproxy/receiver-t.h @@ -65,7 +65,7 @@ struct shard_info { uint nbgroups; /* number of groups in this shard (=#rx); Zero = unused. */ uint nbthreads; /* number of threads in this shard (>=nbgroups) */ struct receiver *ref; /* first one, reference for FDs to duplicate */ - struct receiver *members[MAX_TGROUPS]; /* all members of the shard (one per thread group) */ + struct receiver **members; /* all members of the shard (one per thread group) */ }; /* This describes a receiver with all its characteristics (address, options, etc) */ diff --git a/src/listener.c b/src/listener.c index 69344d356..5e7d556e8 100644 --- a/src/listener.c +++ b/src/listener.c @@ -879,6 +879,11 @@ struct shard_info *shard_info_attach(struct receiver *rx, struct shard_info *si) return NULL; si->ref = rx; + si->members = calloc(global.nbtgroups, sizeof(*si->members)); + if (si->members == NULL) { + free(si); + return NULL; + } } rx->shard_info = si; @@ -921,8 +926,10 @@ void shard_info_detach(struct receiver *rx) si->members[si->nbgroups] = NULL; si->ref = si->members[0]; - if (!si->nbgroups) + if (!si->nbgroups) { + free(si->members); free(si); + } } /* clones listener and returns the new one. All dynamically allocated