summaryrefslogtreecommitdiff
path: root/lib/thread.c
diff options
context:
space:
mode:
authorSpantik <mtspantik@gmail.com>2019-10-14 05:17:29 -0700
committerSpantik <mtspantik@gmail.com>2019-10-15 01:47:30 -0700
commite985cda017fff6a99ee61c9bcb61ce2f5aea7d3f (patch)
treeced684292ff89dae5faa517cbf8162203a6df131 /lib/thread.c
parentd563896dada99f3474d428f928786cbfde936fee (diff)
lib: Clean up the index that is being used for storing FD and events.
When POLLNVAL is received for a FD then that FD is removed from the pfd array and also array is rearranged using memmove. When memmove is used then unused index are not cleanedup. When a new FD takes up that index then it ends up using stale events without any handler set for the same. Signed-off-by: Santosh P K <sapk@vmware.com>
Diffstat (limited to 'lib/thread.c')
-rw-r--r--lib/thread.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/thread.c b/lib/thread.c
index 90c794e88d..6669952ff4 100644
--- a/lib/thread.c
+++ b/lib/thread.c
@@ -975,6 +975,8 @@ static void thread_cancel_rw(struct thread_master *master, int fd, short state)
(master->handler.pfdcount - i - 1)
* sizeof(struct pollfd));
master->handler.pfdcount--;
+ master->handler.pfds[master->handler.pfdcount].fd = 0;
+ master->handler.pfds[master->handler.pfdcount].events = 0;
}
/* If we have the same pollfd in the copy, perform the same operations,
@@ -989,6 +991,8 @@ static void thread_cancel_rw(struct thread_master *master, int fd, short state)
(master->handler.copycount - i - 1)
* sizeof(struct pollfd));
master->handler.copycount--;
+ master->handler.copy[master->handler.copycount].fd = 0;
+ master->handler.copy[master->handler.copycount].events = 0;
}
}
@@ -1292,11 +1296,15 @@ static void thread_process_io(struct thread_master *m, unsigned int num)
(m->handler.pfdcount - i - 1)
* sizeof(struct pollfd));
m->handler.pfdcount--;
+ m->handler.pfds[m->handler.pfdcount].fd = 0;
+ m->handler.pfds[m->handler.pfdcount].events = 0;
memmove(pfds + i, pfds + i + 1,
(m->handler.copycount - i - 1)
* sizeof(struct pollfd));
m->handler.copycount--;
+ m->handler.copy[m->handler.copycount].fd = 0;
+ m->handler.copy[m->handler.copycount].events = 0;
i--;
}