From 534f6657f8066ce86236ebe0a7abb0dc7575ab86 Mon Sep 17 00:00:00 2001 From: Niels Provos Date: Fri, 25 Jul 2008 01:19:53 +0000 Subject: [PATCH] from trunk: fix off by one errors in devpoll; from Ian Bell svn:r922 --- ChangeLog | 1 + devpoll.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 78b27b21..b42bcdf5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,6 +13,7 @@ Changes in 1.4.6-stable: o Fix a memory leak when using signals for some event bases; reported by Alexander Drozdov. o Add libevent.vcproj file to distribution to help with Windows build. o Fix a problem with epoll() and reinit; problem report by Alexander Drozdov. + o Fix off-by-one errors in devpoll; from Ian Bell Changes in 1.4.5-stable: o Fix connection keep-alive behavior for HTTP/1.0 diff --git a/devpoll.c b/devpoll.c index ebcac878..513065ef 100644 --- a/devpoll.c +++ b/devpoll.c @@ -139,7 +139,7 @@ devpoll_init(struct event_base *base) if (getrlimit(RLIMIT_NOFILE, &rl) == 0 && rl.rlim_cur != RLIM_INFINITY) - nfiles = rl.rlim_cur - 1; + nfiles = rl.rlim_cur; /* Initialize the kernel queue */ if ((dpfd = open("/dev/poll", O_RDWR)) == -1) { @@ -187,12 +187,12 @@ devpoll_recalc(struct event_base *base, void *arg, int max) { struct devpollop *devpollop = arg; - if (max > devpollop->nfds) { + if (max >= devpollop->nfds) { struct evdevpoll *fds; int nfds; nfds = devpollop->nfds; - while (nfds < max) + while (nfds <= max) nfds <<= 1; fds = realloc(devpollop->fds, nfds * sizeof(struct evdevpoll));