]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: receiver: Dynamically alloc the "members" field of shard_info
authorOlivier Houchard <ohouchard@haproxy.com>
Wed, 7 Jan 2026 01:57:06 +0000 (02:57 +0100)
committerOlivier Houchard <ohouchard@haproxy.com>
Mon, 12 Jan 2026 08:32:27 +0000 (09:32 +0100)
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
src/listener.c

index d1897de5130fc2c0f1feb7e132c56fa55a217198..976cc70c74993a33d443290d19ce6b1564e3a187 100644 (file)
@@ -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) */
index 69344d356a6d23c6469f3aa0a3a6fb0a0d9dccb4..5e7d556e846837aac78d036d7ba3bff23aac7e08 100644 (file)
@@ -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 <src> and returns the new one. All dynamically allocated