Skip to content

Commit

Permalink
Oneshot crash fix: cache off oneshot status before running on_event (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
ColdenCullen authored Sep 22, 2023
1 parent 9671abe commit 81c47bc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion source/bsd/event_loop_kqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,12 @@ int tlb_evl_handle_events(struct tlb_event_loop *loop, size_t budget, int timeou

TLB_LOG_EVENT(sub, "Handling");

/* Cache this off because sub can become invalid during on_event */
const bool is_oneshot = sub->sub_mode & TLB_SUB_ONESHOT;
sub->oneshot_state = TLB_STATE_RUNNING;
sub->on_event(sub, s_events_from_kevent(ev), sub->userdata);

if (sub->sub_mode & TLB_SUB_ONESHOT) {
if (is_oneshot) {
switch (sub->oneshot_state) {
case TLB_STATE_SUBBED:
/* Not possible */
Expand Down
4 changes: 2 additions & 2 deletions source/linux/event_loop_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ int tlb_evl_handle_events(struct tlb_event_loop *loop, size_t budget, int timeou
TLB_LOG_EVENT(sub, "Handling");

/* Cache this off because sub can become invalid during on_event */
const uint8_t sub_mode = sub->sub_mode;
const bool is_oneshot = sub->sub_mode & TLB_SUB_ONESHOT;
sub->oneshot_state = TLB_STATE_RUNNING;
sub->on_event(sub, s_events_from_epoll(event), sub->userdata);

if (sub_mode & TLB_SUB_ONESHOT) {
if (is_oneshot) {
switch ((enum tlb_sub_state)sub->oneshot_state) {
case TLB_STATE_SUBBED:
/* Not possible */
Expand Down

0 comments on commit 81c47bc

Please sign in to comment.