diff --git a/src/connector.c b/src/connector.c index 2acaf19c..35289338 100644 --- a/src/connector.c +++ b/src/connector.c @@ -293,12 +293,13 @@ void *receiver(void *arg) { conn_instance_t *ci = (conn_instance_t *)arg; client_instance_t *client, *tmp; - struct pollfd fds[65536]; - int ret, nfds, i; + int ret, nfds, i, maxfds = 1; + struct pollfd *fds; bool update; rename_proc("creceiver"); + fds = ckalloc(sizeof(struct pollfd)); /* First fd is reserved for the accepting socket */ fds[0].fd = ci->serverfd; fds[0].events = POLLIN; @@ -314,6 +315,14 @@ rebuild_fds: client->id); continue; } + if (nfds >= maxfds) { + maxfds = nfds + 1; + fds = realloc(fds, sizeof(struct pollfd) * maxfds); + if (unlikely(!fds)) { + LOGEMERG("FATAL: Failed to realloc fds in receiver!"); + goto out; + } + } fds[nfds].fd = client->fd; fds[nfds].events = POLLIN; fds[nfds].revents = 0; @@ -372,6 +381,7 @@ repoll: goto rebuild_fds; goto repoll; out: + free(fds); return NULL; }