patch 8.2.2433: opening cmdline window gives error in BufLeave autocommand

Problem:    Opening cmdline window gives error in BufLeave autocommand.
Solution:   Reset cmdwin_type when triggering the autocommand.
diff --git a/src/ex_cmds.c b/src/ex_cmds.c
index 12219e7..b678f66 100644
--- a/src/ex_cmds.c
+++ b/src/ex_cmds.c
@@ -2710,6 +2710,12 @@
 	 */
 	if (buf != curbuf)
 	{
+#ifdef FEAT_CMDWIN
+	    int save_cmdwin_type = cmdwin_type;
+
+	    // BufLeave applies to the old buffer.
+	    cmdwin_type = 0;
+#endif
 	    /*
 	     * Be careful: The autocommands may delete any buffer and change
 	     * the current buffer.
@@ -2724,6 +2730,9 @@
 		new_name = vim_strsave(buf->b_fname);
 	    set_bufref(&au_new_curbuf, buf);
 	    apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
+#ifdef FEAT_CMDWIN
+	    cmdwin_type = save_cmdwin_type;
+#endif
 	    if (!bufref_valid(&au_new_curbuf))
 	    {
 		// new buffer has been deleted