diff options
author | Attila Molnar <attilamolnar@hush.com> | 2014-02-05 17:51:03 +0100 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-02-05 17:51:03 +0100 |
commit | 594b9e031c9d9c209ab8d2475255442c6eb7a343 (patch) | |
tree | c8d957e2fb19493a4bbe8bf4f014e1b720427942 /src/socketengines/socketengine_kqueue.cpp | |
parent | da812566e80811b7f9a190feb0913464ba9f0069 (diff) |
Fix oversight in 3752b3f59d5216d7dc6221a361efc76b9ad2273d
Diffstat (limited to 'src/socketengines/socketengine_kqueue.cpp')
-rw-r--r-- | src/socketengines/socketengine_kqueue.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/socketengines/socketengine_kqueue.cpp b/src/socketengines/socketengine_kqueue.cpp index 81addd1c2..99d4236e9 100644 --- a/src/socketengines/socketengine_kqueue.cpp +++ b/src/socketengines/socketengine_kqueue.cpp @@ -219,7 +219,11 @@ int KQueueEngine::DispatchEvents() { struct kevent& kev = ke_list[j]; - EventHandler* eh = GetRef(kev.ident); + // Copy these in case the vector gets resized and kev invalidated + const int fd = kev.ident; + const short filter = kev.filter; + + EventHandler* eh = GetRef(fd); if (!eh) continue; @@ -229,7 +233,7 @@ int KQueueEngine::DispatchEvents() eh->HandleEvent(EVENT_ERROR, kev.fflags); continue; } - if (kev.filter == EVFILT_WRITE) + if (filter == EVFILT_WRITE) { WriteEvents++; /* When mask is FD_WANT_FAST_WRITE or FD_WANT_SINGLE_WRITE, @@ -240,11 +244,11 @@ int KQueueEngine::DispatchEvents() SetEventMask(eh, eh->GetEventMask() & ~bits_to_clr); eh->HandleEvent(EVENT_WRITE); - if (eh != GetRef(kev.ident)) + if (eh != GetRef(fd)) // whoops, deleted out from under us continue; } - if (kev.filter == EVFILT_READ) + if (filter == EVFILT_READ) { ReadEvents++; SetEventMask(eh, eh->GetEventMask() & ~FD_READ_WILL_BLOCK); |