patch 8.2.0327: crash when opening and closing two popup terminal windows

Problem:    Crash when opening and closing two popup terminal windows.
Solution:   Check that prevwin is valid. (closes #5707)
diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim
index 20d27bc..fb717f6 100644
--- a/src/testdir/test_terminal.vim
+++ b/src/testdir/test_terminal.vim
@@ -2391,6 +2391,17 @@
   call delete('XtermPopup')
 endfunc
 
+func Test_double_popup_terminal()
+  let buf1 = term_start(&shell, #{hidden: 1})
+  let win1 = popup_create(buf1, {})
+  let buf2 = term_start(&shell, #{hidden: 1})
+  let win2 = popup_create(buf2, {})
+  call popup_close(win1)
+  call popup_close(win2)
+  exe buf1 .. 'bwipe!'
+  exe buf2 .. 'bwipe!'
+endfunc
+
 func Test_issue_5607()
   let wincount = winnr('$')
   exe 'terminal' &shell &shellcmdflag 'exit'