To: vim_dev@googlegroups.com Subject: Patch 8.1.2197 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.1.2197 Problem: ExitPre autocommand may cause accessing freed memory. Solution: Check the window pointer is still valid. (closes #5093) Files: src/testdir/test_exit.vim, src/ex_docmd.c *** ../vim-8.1.2196/src/testdir/test_exit.vim 2019-05-20 22:12:30.720442793 +0200 --- src/testdir/test_exit.vim 2019-10-20 22:12:41.400190382 +0200 *************** *** 40,45 **** --- 40,46 ---- endif call delete('Xtestout') + " ExitPre autocommand splits the window, so that it's no longer the last one. let after =<< trim [CODE] au QuitPre * call writefile(["QuitPre"], "Xtestout", "a") au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") *************** *** 48,53 **** --- 49,75 ---- augroup END quit augroup nasty + au! ExitPre + augroup END + quit + [CODE] + + if RunVim([], after, '') + call assert_equal(['QuitPre', 'ExitPre', 'QuitPre', 'ExitPre'], + \ readfile('Xtestout')) + endif + call delete('Xtestout') + + " ExitPre autocommand splits and closes the window, so that there is still + " one window but it's a different one. + let after =<< trim [CODE] + au QuitPre * call writefile(["QuitPre"], "Xtestout", "a") + au ExitPre * call writefile(["ExitPre"], "Xtestout", "a") + augroup nasty + au ExitPre * split | only + augroup END + quit + augroup nasty au! ExitPre augroup END quit *** ../vim-8.1.2196/src/ex_docmd.c 2019-10-20 21:15:07.457905609 +0200 --- src/ex_docmd.c 2019-10-20 22:27:01.113349181 +0200 *************** *** 4817,4825 **** { apply_autocmds(EVENT_QUITPRE, NULL, NULL, FALSE, wp->w_buffer); ! /* Bail out when autocommands closed the window. ! * Refuse to quit when the buffer in the last window is being closed (can ! * only happen in autocommands). */ if (!win_valid(wp) || curbuf_locked() || (wp->w_buffer->b_nwindows == 1 && wp->w_buffer->b_locked > 0)) --- 4817,4825 ---- { apply_autocmds(EVENT_QUITPRE, NULL, NULL, FALSE, wp->w_buffer); ! // Bail out when autocommands closed the window. ! // Refuse to quit when the buffer in the last window is being closed (can ! // only happen in autocommands). if (!win_valid(wp) || curbuf_locked() || (wp->w_buffer->b_nwindows == 1 && wp->w_buffer->b_locked > 0)) *************** *** 4828,4836 **** if (quit_all || (check_more(FALSE, forceit) == OK && only_one_window())) { apply_autocmds(EVENT_EXITPRE, NULL, NULL, FALSE, curbuf); ! /* Refuse to quit when locked or when the buffer in the last window is ! * being closed (can only happen in autocommands). */ ! if (curbuf_locked() || (curbuf->b_nwindows == 1 && curbuf->b_locked > 0)) return TRUE; } --- 4828,4837 ---- if (quit_all || (check_more(FALSE, forceit) == OK && only_one_window())) { apply_autocmds(EVENT_EXITPRE, NULL, NULL, FALSE, curbuf); ! // Refuse to quit when locked or when the window was closed or the ! // buffer in the last window is being closed (can only happen in ! // autocommands). ! if (!win_valid(wp) || curbuf_locked() || (curbuf->b_nwindows == 1 && curbuf->b_locked > 0)) return TRUE; } *** ../vim-8.1.2196/src/version.c 2019-10-20 21:47:16.817248371 +0200 --- src/version.c 2019-10-20 22:10:28.472636135 +0200 *************** *** 743,744 **** --- 743,746 ---- { /* Add new patch number below this line */ + /**/ + 2197, /**/ -- Bad programs can be written in any language. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///