X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=src%2Fcommon%2Fcompat%2Fcompat-poll.c;h=79fcb7d652b87230815c4d7b6d7146cf8546a9c2;hp=bc79eed0aaa5321c48fcd055858698bcdc5fa375;hb=cfa9a5a2b4a96e0d6a9eeddd2622a6d7c173b7ac;hpb=12d1308838f30af13dc917323a4bcc70b5d97e81 diff --git a/src/common/compat/compat-poll.c b/src/common/compat/compat-poll.c index bc79eed0a..79fcb7d65 100644 --- a/src/common/compat/compat-poll.c +++ b/src/common/compat/compat-poll.c @@ -23,6 +23,8 @@ #include #include +#include +#include #include "poll.h" @@ -168,7 +170,9 @@ int compat_poll_add(struct lttng_poll_event *events, int fd, /* Check for a needed resize of the array. */ if (current->nb_fd > current->alloc_size) { /* Expand it by a power of two of the current size. */ - new_size = current->alloc_size << 1UL; + new_size = max_t(int, + 1U << utils_get_count_order_u32(current->nb_fd), + current->alloc_size << 1UL); ret = resize_poll_event(current, new_size); if (ret < 0) { goto error; @@ -212,7 +216,9 @@ int compat_poll_del(struct lttng_poll_event *events, int fd) * Shrink if nb_fd multiplied by two is <= than the actual size and we * are above the initial size. */ - new_size = current->alloc_size >> 1UL; + new_size = max_t(int, + utils_get_count_order_u32(current->nb_fd) >> 1U, + current->alloc_size >> 1U); ret = resize_poll_event(current, new_size); if (ret < 0) { goto error;