patch 8.2.1905: the wininfo list may contain stale entries

Problem:    The wininfo list may contain stale entries.
Solution:   When closing a window remove any other entry where the window
            pointer is NULL.
diff --git a/src/buffer.c b/src/buffer.c
index 318ce7f..5a5eb9f 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1006,6 +1006,22 @@
 }
 
 /*
+ * Free one wininfo_T.
+ */
+    void
+free_wininfo(wininfo_T *wip)
+{
+    if (wip->wi_optset)
+    {
+	clear_winopt(&wip->wi_opt);
+#ifdef FEAT_FOLDING
+	deleteFoldRecurse(&wip->wi_folds);
+#endif
+    }
+    vim_free(wip);
+}
+
+/*
  * Free the b_wininfo list for buffer "buf".
  */
     static void
@@ -1017,14 +1033,7 @@
     {
 	wip = buf->b_wininfo;
 	buf->b_wininfo = wip->wi_next;
-	if (wip->wi_optset)
-	{
-	    clear_winopt(&wip->wi_opt);
-#ifdef FEAT_FOLDING
-	    deleteFoldRecurse(&wip->wi_folds);
-#endif
-	}
-	vim_free(wip);
+	free_wininfo(wip);
     }
 }