X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fcommon%2Fcompat%2Fpoll.cpp;h=dfe05d59eec70afd3aaf6e9daffe83f733ac5132;hb=9a30ba1da4e6d59eb30c6535a9dd04cd599e6fae;hp=ee4fc012c982af330429a7d7d81a16b22259bd31;hpb=21cf9b6b1843774306a76f4dccddddd706b64f79;p=lttng-tools.git diff --git a/src/common/compat/poll.cpp b/src/common/compat/poll.cpp index ee4fc012c..dfe05d59e 100644 --- a/src/common/compat/poll.cpp +++ b/src/common/compat/poll.cpp @@ -2,7 +2,7 @@ * Copyright (C) 2011 EfficiOS Inc. * Copyright (C) 2019 Yannick Lamarre * - * SPDX-License-Identifier: GPL-2.0-only + * SPDX-License-Identifier: LGPL-2.1-only * */ @@ -10,14 +10,14 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include -#include "poll.h" +#include "poll.hpp" -#if HAVE_EPOLL +#ifdef HAVE_EPOLL #include #include @@ -71,11 +71,11 @@ error: /* * Create epoll set and allocate returned events structure. */ -int compat_epoll_create(struct lttng_poll_event *events, int size, int flags) +int compat_epoll_create(struct lttng_poll_event *events, int count, int flags) { int ret; - if (events == NULL || size <= 0) { + if (events == NULL || count <= 0) { goto error; } @@ -86,11 +86,11 @@ int compat_epoll_create(struct lttng_poll_event *events, int size, int flags) } /* Don't bust the limit here */ - if (size > poll_max_size) { - size = poll_max_size; + if (count > poll_max_size) { + count = poll_max_size; } - ret = compat_glibc_epoll_create(size, flags); + ret = compat_glibc_epoll_create(count, flags); if (ret < 0) { /* At this point, every error is fatal */ PERROR("epoll_create1"); @@ -100,13 +100,13 @@ int compat_epoll_create(struct lttng_poll_event *events, int size, int flags) events->epfd = ret; /* This *must* be freed by using lttng_poll_free() */ - events->events = (epoll_event *) zmalloc(size * sizeof(struct epoll_event)); + events->events = calloc(count); if (events->events == NULL) { PERROR("zmalloc epoll set"); goto error_close; } - events->alloc_size = events->init_size = size; + events->alloc_size = events->init_size = count; events->nb_fd = 0; return 0; @@ -455,17 +455,17 @@ int compat_poll_create(struct lttng_poll_event *events, int size) wait = &events->wait; /* This *must* be freed by using lttng_poll_free() */ - wait->events = (struct pollfd *) zmalloc(size * sizeof(struct pollfd)); + wait->events = calloc(size); if (wait->events == NULL) { - PERROR("zmalloc struct pollfd"); + PERROR("Failed to allocate wait events array during poll initialization"); goto error; } wait->alloc_size = wait->init_size = size; - current->events = (struct pollfd *) zmalloc(size * sizeof(struct pollfd)); + current->events = calloc(size); if (current->events == NULL) { - PERROR("zmalloc struct current pollfd"); + PERROR("Failed to allocate current events array during poll initialization"); goto error; }