diff src/time.c @ 30695:b9cc46461994 v9.0.0682

patch 9.0.0682: crash when popup with deleted timer is closed Commit: https://github.com/vim/vim/commit/cf3d0eaf47a56a52b355d8faf4e59685396f9c05 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Oct 7 11:20:29 2022 +0100 patch 9.0.0682: crash when popup with deleted timer is closed Problem: Crash when popup with deleted timer is closed. (Igbanam Ogbuluijah) Solution: Check the timer still exists. (closes #11301)
author Bram Moolenaar <Bram@vim.org>
date Fri, 07 Oct 2022 12:30:07 +0200
parents 029c59bf78f1
children 1213e3988168
line wrap: on
line diff
--- a/src/time.c
+++ b/src/time.c
@@ -777,15 +777,27 @@ set_ref_in_timer(int copyID)
     return abort;
 }
 
+/*
+ * Return TRUE if "timer" exists in the list of timers.
+ */
+    int
+timer_valid(timer_T *timer)
+{
+    if (timer == NULL)
+	return FALSE;
+    for (timer_T *t = first_timer; t != NULL; t = t->tr_next)
+	if (t == timer)
+	    return TRUE;
+    return FALSE;
+}
+
 # if defined(EXITFREE) || defined(PROTO)
     void
 timer_free_all()
 {
-    timer_T *timer;
-
     while (first_timer != NULL)
     {
-	timer = first_timer;
+	timer_T *timer = first_timer;
 	remove_timer(timer);
 	free_timer(timer);
     }