patch 8.0.0948: crash if timer closes window while dragging status line
Problem: Crash if timer closes window while dragging status line.
Solution: Check if the window still exists. (Yasuhiro Matsumoto, closes
#1979)
diff --git a/src/ui.c b/src/ui.c
index 907390e..ddae372 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -2709,6 +2709,8 @@
#ifdef FEAT_WINDOWS
/* find the window where the row is in */
wp = mouse_find_win(&row, &col);
+ if (wp == NULL)
+ return IN_UNKNOWN;
#else
wp = firstwin;
#endif
@@ -3117,11 +3119,13 @@
/*
* Find the window at screen position "*rowp" and "*colp". The positions are
* updated to become relative to the top-left of the window.
+ * Returns NULL when something is wrong.
*/
win_T *
mouse_find_win(int *rowp, int *colp UNUSED)
{
frame_T *fp;
+ win_T *wp;
fp = topframe;
*rowp -= firstwin->w_winrow;
@@ -3148,7 +3152,12 @@
}
}
}
- return fp->fr_win;
+ /* When using a timer that closes a window the window might not actually
+ * exist. */
+ FOR_ALL_WINDOWS(wp)
+ if (wp == fp->fr_win)
+ return wp;
+ return NULL;
}
#endif
@@ -3171,6 +3180,8 @@
#ifdef FEAT_WINDOWS
/* find the window where the row is in */
wp = mouse_find_win(&row, &col);
+ if (wp == NULL)
+ return IN_UNKNOWN;
#else
wp = firstwin;
#endif