]> granicus.if.org Git - vim/commitdiff
patch 7.4.1860 v7.4.1860
authorBram Moolenaar <Bram@vim.org>
Tue, 31 May 2016 19:13:04 +0000 (21:13 +0200)
committerBram Moolenaar <Bram@vim.org>
Tue, 31 May 2016 19:13:04 +0000 (21:13 +0200)
Problem:    Using a partial for timer_start() may cause a crash.
Solution:   Set the copyID in timer objects. (Ozaki Kiichi)

src/eval.c
src/ex_cmds2.c
src/proto/ex_cmds2.pro
src/testdir/test_timers.vim
src/version.c

index 3578c9997cd75da4b5e6b1a774e3973d28d3ebdd..d30a766531788b53bbfb9ef6f04aa1748a757399 100644 (file)
@@ -7046,6 +7046,10 @@ garbage_collect(int testing)
     abort = abort || set_ref_in_nb_channel(copyID);
 #endif
 
+#ifdef FEAT_TIMERS
+    abort = abort || set_ref_in_timer(copyID);
+#endif
+
     if (!abort)
     {
        /*
index a90fe7d8c6565e08f66a3fe647147a0300e4e3c9..9adaea357d68c6dc9457b1f0dc2093cb3d25c17d 100644 (file)
@@ -1252,6 +1252,25 @@ stop_timer(timer_T *timer)
     remove_timer(timer);
     free_timer(timer);
 }
+
+/*
+ * Mark references in partials of timers.
+ */
+    int
+set_ref_in_timer(int copyID)
+{
+    int                abort = FALSE;
+    timer_T    *timer;
+    typval_T   tv;
+
+    for (timer = first_timer; timer != NULL; timer = timer->tr_next)
+    {
+       tv.v_type = VAR_PARTIAL;
+       tv.vval.v_partial = timer->tr_partial;
+       abort = abort || set_ref_in_item(&tv, copyID, NULL, NULL);
+    }
+    return abort;
+}
 # endif
 
 #if defined(FEAT_SYN_HL) && defined(FEAT_RELTIME) && defined(FEAT_FLOAT)
index 5e5b4d4b7396771729e7821b5340dd9e270c5393..8d9b72a24817cfbeb2221b9e1493ab3a37155ed5 100644 (file)
@@ -22,6 +22,7 @@ timer_T *create_timer(long msec, int repeats);
 long check_due_timer(void);
 timer_T *find_timer(int id);
 void stop_timer(timer_T *timer);
+int set_ref_in_timer(int copyID);
 void profile_divide(proftime_T *tm, int count, proftime_T *tm2);
 void profile_add(proftime_T *tm, proftime_T *tm2);
 void profile_self(proftime_T *self, proftime_T *total, proftime_T *children);
index 7ef51e5b5d881769347fa68298ff178d66d47c1c..0969377c87b97524bde24e1cdb0cf218cad0bef2 100644 (file)
@@ -8,6 +8,10 @@ func MyHandler(timer)
   let s:val += 1
 endfunc
 
+func MyHandlerWithLists(lists, timer)
+  let x = string(a:lists)
+endfunc
+
 func Test_oneshot()
   let s:val = 0
   let timer = timer_start(50, 'MyHandler')
@@ -42,4 +46,10 @@ func Test_with_partial_callback()
   sleep 200m
   call assert_equal(1, s:val)
 endfunc
+
+func Test_retain_partial()
+  call timer_start(100, function('MyHandlerWithLists', [['a']]))
+  call test_garbagecollect_now()
+  sleep 200m
+endfunc
 " vim: ts=2 sw=0 et
index eb9f2c7112ead56a2fec8f80bd591b7ca6e1da96..515f5187625e8f1525c3a317ec3848edda836ea8 100644 (file)
@@ -753,6 +753,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1860,
 /**/
     1859,
 /**/