summaryrefslogtreecommitdiffstats
path: root/src/ex_cmds2.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2016-09-01 21:26:20 +0200
committerBram Moolenaar <Bram@vim.org>2016-09-01 21:26:20 +0200
commit417ccd7138d4d230d328de8b0d3892dd82ff1bee (patch)
tree9dbbb0b04dd9a3eba03b1d949348d1616b878aef /src/ex_cmds2.c
parent779f2fc3a7468e273897d2fd0672315812a2e3da (diff)
patch 7.4.2304v7.4.2304
Problem: In a timer callback the timer itself can't be found or stopped. (Thinca) Solution: Do not remove the timer from the list, remember whether it was freed.
Diffstat (limited to 'src/ex_cmds2.c')
-rw-r--r--src/ex_cmds2.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/ex_cmds2.c b/src/ex_cmds2.c
index 85513af296..a76b055220 100644
--- a/src/ex_cmds2.c
+++ b/src/ex_cmds2.c
@@ -1090,6 +1090,9 @@ profile_zero(proftime_T *tm)
static timer_T *first_timer = NULL;
static int last_timer_id = 0;
+static timer_T *current_timer = NULL;
+static int free_current_timer = FALSE;
+
/*
* Insert a timer in the list of timers.
*/
@@ -1121,8 +1124,13 @@ remove_timer(timer_T *timer)
static void
free_timer(timer_T *timer)
{
- free_callback(timer->tr_callback, timer->tr_partial);
- vim_free(timer);
+ if (timer == current_timer)
+ free_current_timer = TRUE;
+ else
+ {
+ free_callback(timer->tr_callback, timer->tr_partial);
+ vim_free(timer);
+ }
}
/*
@@ -1200,18 +1208,23 @@ check_due_timer(void)
# endif
if (this_due <= 1)
{
- remove_timer(timer);
+ current_timer = timer;
+ free_current_timer = FALSE;
timer_callback(timer);
+ current_timer = NULL;
+
did_one = TRUE;
- if (timer->tr_repeat != 0)
+ if (timer->tr_repeat != 0 && !free_current_timer)
{
profile_setlimit(timer->tr_interval, &timer->tr_due);
if (timer->tr_repeat > 0)
--timer->tr_repeat;
- insert_timer(timer);
}
else
+ {
free_timer(timer);
+ remove_timer(timer);
+ }
/* the callback may do anything, start all over */
break;
}