Merge pull request #8383 from bfredl/timercrash

always run timer close callback after due callback
This commit is contained in:
Björn Linse 2018-05-15 07:47:33 +02:00 committed by GitHub
commit de7a0bdc35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -17039,7 +17039,8 @@ static void timer_stop(timer_T *timer)
time_watcher_close(&timer->tw, timer_close_cb); time_watcher_close(&timer->tw, timer_close_cb);
} }
// invoked on next event loop tick, so queue is empty // This will be run on the main loop after the last timer_due_cb, so at this
// point it is safe to free the callback.
static void timer_close_cb(TimeWatcher *tw, void *data) static void timer_close_cb(TimeWatcher *tw, void *data)
{ {
timer_T *timer = (timer_T *)data; timer_T *timer = (timer_T *)data;

View File

@ -61,10 +61,17 @@ static void time_watcher_cb(uv_timer_t *handle)
CREATE_EVENT(watcher->events, time_event, 1, watcher); CREATE_EVENT(watcher->events, time_event, 1, watcher);
} }
static void close_event(void **argv)
{
TimeWatcher *watcher = argv[0];
watcher->close_cb(watcher, watcher->data);
}
static void close_cb(uv_handle_t *handle) static void close_cb(uv_handle_t *handle)
FUNC_ATTR_NONNULL_ALL
{ {
TimeWatcher *watcher = handle->data; TimeWatcher *watcher = handle->data;
if (watcher->close_cb) { if (watcher->close_cb) {
watcher->close_cb(watcher, watcher->data); CREATE_EVENT(watcher->events, close_event, 1, watcher);
} }
} }