core: protect against changes to the pollfd list during handle_events
authorNathan Hjelm <hjelmn@google.com>
Wed, 14 Aug 2019 21:00:41 +0000 (14:00 -0700)
committerNathan Hjelm <hjelmn@google.com>
Wed, 14 Aug 2019 21:00:41 +0000 (14:00 -0700)
commitdd7df2b75118c920cb21b4442983168e8b2f14ac
treef5f156131b199becd8a24c34669f18e2d5d79eec
parentafadbc7a89f49b70a09d0d809853777ce3a135bf
core: protect against changes to the pollfd list during handle_events

It is possible a file descriptor to be removed due to a close and the
same file descriptor value to be added during the same event loop. This
can cause the backend to get a stale revent and incorrectly remove the
file descriptor.

This commit addresses the issue by delaying the actual removal of the
ipollfds entry until just before the backend handle_events is called.
handle_events then goes through the list of closed fds and clears out
the revents associated with the closed file descriptor.

Signed-off-by: Nathan Hjelm <hjelmn@google.com>
libusb/io.c
libusb/libusbi.h
libusb/version_nano.h