diff -r 26f6d8cc2749 Modules/selectmodule.c --- a/Modules/selectmodule.c Thu Jan 28 15:44:10 2016 +0100 +++ b/Modules/selectmodule.c Thu Jan 28 16:09:10 2016 +0100 @@ -1490,7 +1490,8 @@ pyepoll_poll(pyEpoll_Object *self, PyObj int maxevents = -1; int nfds, i; PyObject *elist = NULL, *etuple = NULL; - struct epoll_event *evs = NULL; + struct epoll_event evs_nomalloc[FD_SETSIZE-1]; + struct epoll_event *evs = evs_nomalloc; _PyTime_t timeout, ms, deadline; if (self->epfd < 0) @@ -1530,17 +1531,19 @@ pyepoll_poll(pyEpoll_Object *self, PyObj if (maxevents == -1) { maxevents = FD_SETSIZE-1; } - else if (maxevents < 1) { + else if (maxevents == 0) { PyErr_Format(PyExc_ValueError, "maxevents must be greater than 0, got %d", maxevents); return NULL; } - evs = PyMem_New(struct epoll_event, maxevents); - if (evs == NULL) { - PyErr_NoMemory(); - return NULL; + if (maxevents >= FD_SETSIZE) { + evs = PyMem_New(struct epoll_event, maxevents); + if (evs == NULL) { + PyErr_NoMemory(); + return NULL; + } } do { @@ -1587,7 +1590,9 @@ pyepoll_poll(pyEpoll_Object *self, PyObj } error: - PyMem_Free(evs); + if (evs != evs_nomalloc) { + PyMem_Free(evs); + } return elist; }