# HG changeset patch # User Bram Moolenaar # Date 1582913704 -3600 # Node ID 9f07a6c172f2a82c5910e7c057038d39a72aff9e # Parent a31e293bd46436b8d239aeef7201a6779943a3ca patch 8.2.0327: crash when opening and closing two popup terminal windows Commit: https://github.com/vim/vim/commit/80ae880f5fed8022c69d05dd1efee49259929cb5 Author: Bram Moolenaar Date: Fri Feb 28 19:11:18 2020 +0100 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 https://github.com/vim/vim/issues/5707) diff --git a/src/popupwin.c b/src/popupwin.c --- a/src/popupwin.c +++ b/src/popupwin.c @@ -2114,9 +2114,31 @@ popup_close_and_callback(win_T *wp, typv #ifdef FEAT_TERMINAL if (wp == curwin && curbuf->b_term != NULL) { - // Closing popup window with a terminal: put focus back on the previous - // window. - win_enter(prevwin, FALSE); + win_T *owp; + + // Closing popup window with a terminal: put focus back on the first + // that works: + // - another popup window with a terminal + // - the previous window + // - the first one. + for (owp = first_popupwin; owp != NULL; owp = owp->w_next) + if (owp != curwin && owp->w_buffer->b_term != NULL) + break; + if (owp != NULL) + win_enter(owp, FALSE); + else + { + for (owp = curtab->tp_first_popupwin; owp != NULL; + owp = owp->w_next) + if (owp != curwin && owp->w_buffer->b_term != NULL) + break; + if (owp != NULL) + win_enter(owp, FALSE); + else if (win_valid(prevwin)) + win_enter(prevwin, FALSE); + else + win_enter(firstwin, FALSE); + } } #endif diff --git a/src/testdir/test_terminal.vim b/src/testdir/test_terminal.vim --- a/src/testdir/test_terminal.vim +++ b/src/testdir/test_terminal.vim @@ -2391,6 +2391,17 @@ func Test_terminal_in_popup() 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' diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -739,6 +739,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 327, +/**/ 326, /**/ 325,