X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Fcompat%2Fcompat-epoll.c;h=903a9f8256eeafad9e678f565ba6c1b60f0e9c2a;hb=cfa9a5a2b4a96e0d6a9eeddd2622a6d7c173b7ac;hp=f014a0d783d434f57fc95a5c17e126f62946e74e;hpb=94cc2fd1d4c93bf52c9142999ad0355ad7bc7323;p=lttng-tools.git diff --git a/src/common/compat/compat-epoll.c b/src/common/compat/compat-epoll.c index f014a0d78..903a9f825 100644 --- a/src/common/compat/compat-epoll.c +++ b/src/common/compat/compat-epoll.c @@ -27,6 +27,8 @@ #include #include +#include +#include #include "poll.h" @@ -201,11 +203,15 @@ int compat_epoll_wait(struct lttng_poll_event *events, int timeout) */ if (events->nb_fd > events->alloc_size) { /* Expand if the nb_fd is higher than the actual size. */ - new_size = events->alloc_size << 1UL; + new_size = max_t(uint32_t, + 1U << utils_get_count_order_u32(events->nb_fd), + events->alloc_size << 1UL); } else if ((events->nb_fd << 1UL) <= events->alloc_size && events->nb_fd >= events->init_size) { /* Shrink if nb_fd multiplied by two is <= than the actual size. */ - new_size = events->alloc_size >> 1UL; + new_size = max_t(uint32_t, + utils_get_count_order_u32(events->nb_fd) >> 1U, + events->alloc_size >> 1U); } else { /* Indicate that we don't want to resize. */ new_size = 0;