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.
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) */
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;
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