Prevent fd leaks in EVFILT_READ/WRITE

This commit is contained in:
Lubos Dolezel 2020-03-22 19:17:58 +01:00
parent cf2248b1ed
commit d534499fdb
2 changed files with 9 additions and 1 deletions

View File

@ -228,7 +228,11 @@ int
evfilt_read_knote_delete(struct filter *filt, struct knote *kn)
{
if (kn->kev.flags & EV_DISABLE)
return (0);
{
(void) __close_for_kqueue(kn->kdata.kn_dupfd);
kn->kdata.kn_dupfd = -1;
return 0;
}
if ((kn->kn_flags & KNFL_REGULAR_FILE) && (kn->kdata.kn_eventfd != -1)) {
if (epoll_ctl(kn->kn_epollfd, EPOLL_CTL_DEL, kn->kdata.kn_eventfd, NULL) < 0) {

View File

@ -120,7 +120,11 @@ int
evfilt_socket_knote_delete(struct filter *filt, struct knote *kn)
{
if (kn->kev.flags & EV_DISABLE)
{
(void) __close_for_kqueue(kn->kdata.kn_dupfd);
kn->kdata.kn_dupfd = -1;
return (0);
}
else {
if (epoll_ctl(kn->kn_epollfd, EPOLL_CTL_DEL, kn->kdata.kn_dupfd, NULL) < 0) {
dbg_perror("epoll_ctl(2)");