From 698a6a9d7d8d9f4bf90287ddf60ebf5325167ec8 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 29 Nov 2015 00:05:56 +0200 Subject: [PATCH] unix/moduselect: poll.register(): Reuse freed entries in poll array. --- unix/moduselect.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/unix/moduselect.c b/unix/moduselect.c index 645e0545d4..80483043bd 100644 --- a/unix/moduselect.c +++ b/unix/moduselect.c @@ -58,7 +58,15 @@ STATIC mp_obj_t poll_register(uint n_args, const mp_obj_t *args) { if (self->len < self->alloc) { i = self->len++; } else { - assert(0); + struct pollfd *entries = self->entries; + for (i = 0; i < self->len; i++, entries++) { + if (entries->fd == -1) { + break; + } + } + if (entries->fd != -1) { + assert(0); + } } self->entries[i].fd = mp_obj_get_int(args[1]);