Call watcher callback as last action for watcher, may delete itself

A watcher callback may be a timeout callback, or similar, that deletes
itself and the watcher.  So we should not dereference anything in the
watcher after the callback.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2018-01-28 13:53:10 +01:00
parent a528405258
commit dd651ae791
+7 -3
View File
@@ -365,9 +365,6 @@ int uev_run(uev_ctx_t *ctx, int flags)
break;
}
if (w->cb)
w->cb(w, w->arg, events & UEV_EVENT_MASK);
if (UEV_CRON_TYPE == w->type) {
if (!w->u.c.when)
uev_timer_stop(w);
@@ -376,6 +373,13 @@ int uev_run(uev_ctx_t *ctx, int flags)
if (!w->u.t.timeout)
uev_timer_stop(w);
}
/*
* NOTE: Must be last action for watcher, the
* callback may delete itself.
*/
if (w->cb)
w->cb(w, w->arg, events & UEV_EVENT_MASK);
}
if (flags & UEV_ONCE)