[PATCH] file descriptor array extension off by 1

Hello,

Running my program inside of valgrind I noticed two problems in version
1.4.9 (problems look to still be there in trunk). I've attached a Problem1
patch for version 1.4.9. Sorry I don't have time right now to solve
Problem2.

Problem1:
Line 268 in epoll.c looks to see if the file descriptor array needs to be
extended, but passes in the wrong argument. 'fd' is passed into
epoll_recalc as the size to expand to, but since the array is zero indexed
it needs to be expanded to 'fd+1' if you intend to access element 'fd'
(which line 273 does).

Solution:
pass 'fd+1' into epoll_recalc.


Problem2:
Resizing the fd array potentially moves the array, invalidating any
existing pointers into the array. Especially user data pointers set with
epoll_ctl at epoll.c:292. The reallocating functionality needs to update
all existing pointers if the array moved.

Thanks,
Kevin Springborn
--- a/epoll.c
+++ b/epoll.c
@@ -267,7 +267,7 @@
 	fd = ev->ev_fd;
 	if (fd >= epollop->nfds) {
 		/* Extent the file descriptor array as necessary */
-		if (epoll_recalc(ev->ev_base, epollop, fd) == -1)
+		if (epoll_recalc(ev->ev_base, epollop, fd+1) == -1)
 			return (-1);
 	}
 	evep = &epollop->fds[fd];
_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users

Reply via email to