Handle null state, don't read/write on error
Need to guard against errors when reading/writing probably, if there is
an error, forgo those events.
Guard against null state (and the byproduct, a segfault), check if the
state is null before utilizing it.
@@ -1702,19 +1702,22 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp timeout) {
} else {
JanetStream *stream = p;
JanetListenerState *state = stream->state;
+ if (NULL != state) {
state->event = events + i;
JanetAsyncStatus statuses[4];
for (int i = 0; i < 4; i++)
statuses[i] = JANET_ASYNC_STATUS_NOT_DONE;
+ if (!(events[i].flags & EV_ERROR)) {
if (events[i].filter == EVFILT_WRITE)
statuses[0] = state->machine(state, JANET_ASYNC_EVENT_WRITE);
if (events[i].filter == EVFILT_READ)
statuses[1] = state->machine(state, JANET_ASYNC_EVENT_READ);
- if (events[i].flags & EV_ERROR)
- statuses[2] = state->machine(state, JANET_ASYNC_EVENT_ERR);
if ((events[i].flags & EV_EOF) && !(events[i].data > 0))
statuses[3] = state->machine(state, JANET_ASYNC_EVENT_HUP);
+ } else {
+ statuses[2] = state->machine(state, JANET_ASYNC_EVENT_ERR);
+ }
if(statuses[0] == JANET_ASYNC_STATUS_DONE ||
statuses[1] == JANET_ASYNC_STATUS_DONE ||
statuses[2] == JANET_ASYNC_STATUS_DONE ||
@@ -1723,6 +1726,7 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp timeout) {
}
}
}
+}
void janet_ev_init(void) {
janet_ev_init_common();
