]> granicus.if.org Git - vim/commitdiff
patch 8.2.2465: using freed memory in :psearch v8.2.2465
authorBram Moolenaar <Bram@vim.org>
Wed, 3 Feb 2021 22:04:46 +0000 (23:04 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 3 Feb 2021 22:04:46 +0000 (23:04 +0100)
Problem:    Using freed memory in :psearch. (houyunsong)
Solution:   Check the current window is still valid.  Fix flaky test.

src/search.c
src/testdir/test_autocmd.vim
src/version.c

index 3a4d4589a0e87a31ea257adc7c9344bf1791365d..d8c21f43c739cc7232b49b968f9ef690139a733d 100644 (file)
@@ -3864,6 +3864,8 @@ search_line:
 #if defined(FEAT_QUICKFIX)
                        if (g_do_tagpreview != 0)
                        {
+                           if (!win_valid(curwin_save))
+                               break;
                            if (!GETFILE_SUCCESS(getfile(
                                           curwin_save->w_buffer->b_fnum, NULL,
                                                     NULL, TRUE, lnum, FALSE)))
index b1a235c8f2c0ed84f591b8ab19a303dc6747fb14..cb5c62f522207bbf004b5a9787370261db5617cc 100644 (file)
@@ -60,7 +60,7 @@ if has('timers')
     let g:triggered = 0
     au CursorHoldI * let g:triggered += 1
     set updatetime=20
-    call timer_start(100, 'ExitInsertMode')
+    call timer_start(200, 'ExitInsertMode')
     call feedkeys('a', 'x!')
     call assert_equal(1, g:triggered)
     unlet g:triggered
@@ -2413,9 +2413,18 @@ func Test_autocmd_was_using_freed_memory()
 
   pedit xx
   n x
-  au WinEnter * quit
+  augroup winenter
+    au WinEnter * if winnr('$') > 2 | quit | endif
+  augroup END
   split
-  au! WinEnter
+
+  augroup winenter
+    au! WinEnter
+  augroup END
+
+  bwipe xx
+  bwipe x
+  pclose
 endfunc
 
 func Test_BufWrite_lockmarks()
@@ -2737,4 +2746,17 @@ func Test_autocmd_closes_window()
   au! BufWinLeave
 endfunc
 
+func Test_autocmd_quit_psearch()
+  sn aa bb
+  augroup aucmd_win_test
+    au!
+    au BufEnter,BufLeave,BufNew,WinEnter,WinLeave,WinNew * if winnr('$') > 1 | q | endif
+  augroup END
+  ps /
+
+  augroup aucmd_win_test
+    au!
+  augroup END
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index a93b81a4107b5be9641b13f7d2227d090c0a1bb1..7f672301ecd3babfcbf989cd0b884e01419a691b 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2465,
 /**/
     2464,
 /**/