[zeromq-dev] setting the CLOEXEC flag for eventfd and epoll instances?

zmqdev zmqdev at amitego.com
Fri Dec 2 14:19:43 CET 2016

while investigating a problem involving fork() and zeromq, I found some 
file descriptor leaks.

1. The function

	zmq::epoll_t::epoll_t (const zmq::ctx_t &ctx_)

in src/epoll.cpp creates an epoll instance with

	epoll_fd = epoll_create(1);

SUGGESTION: replace with

	epoll_fd = epoll_create1(EPOLL_CLOEXEC);

2. The function

	zmq::signaler_t::make_fdpair (fd_t *r_, fd_t *w_)

in src/signaler.cpp creates an eventfd object with

#if defined ZMQ_HAVE_EVENTFD
	fd_t fd = eventfd (0, 0);

SUGGESTION: replace with

#if defined ZMQ_HAVE_EVENTFD
	fd_t fd = eventfd (0, EFD_CLOEXEC);

More information about the zeromq-dev mailing list