[PATCH] ev: fix epoll_init fd leak

Christian Parpart trapni at gentoo.org
Mon Oct 31 12:25:13 CET 2011


On Mon, Oct 31, 2011 at 10:41 AM, Marc Lehmann <schmorp at schmorp.de> wrote:

> On Mon, Oct 31, 2011 at 04:18:22AM +0100, Ben Noordhuis <
> info at bnoordhuis.nl> wrote:
> > epoll_init() leaks a file descriptor if it's called when the process
> > has no open file descriptors.
>
> When there are no open fds, then epoll_create1 will return -1 and will not
> allocate an fd.
>
> If epoll_create1 ever returns 0 you basically have a security issue in your
> program, and it's indeed best to leave it alone.
>
> (fd 0 is always stdin, it's always in use and can never leak).


there are processes, that spawn other processes and first close all
inherited file descriptors, including 0, 1, and 2, because the to be
spawned child process is not meant to have any stdin/stdout/stderr at all
(think of daemons).

And even if you still dislike that fact, it's a manner of good attitude, to
stick on conventions like always checking for < 0 on error instead of <= 0,
as, in fact, epoll_create returns -1 (< 0) on error, and never 0, as 0 is -
in fact - a valid file descriptor.

Best regards,
Christian Parpart.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.schmorp.de/pipermail/libev/attachments/20111031/743ccae5/attachment.html>


More information about the libev mailing list