view src/testdir/test_exit.vim @ 18406:fa6efc49d71f v8.1.2197

patch 8.1.2197: ExitPre autocommand may cause accessing freed memory Commit: https://github.com/vim/vim/commit/34ba06b6e6f94bb46062e6c85dbfdcbb0d255ada Author: Bram Moolenaar <Bram@vim.org> Date: Sun Oct 20 22:27:10 2019 +0200 patch 8.1.2197: ExitPre autocommand may cause accessing freed memory Problem: ExitPre autocommand may cause accessing freed memory. Solution: Check the window pointer is still valid. (closes https://github.com/vim/vim/issues/5093)
author Bram Moolenaar <Bram@vim.org>
date Sun, 20 Oct 2019 22:30:03 +0200
parents 9c90cf08cfa8
children 08940efa6b4e
line wrap: on
line source

" Tests for exiting Vim.

source shared.vim

func Test_exiting()
  let after =<< trim [CODE]
    au QuitPre * call writefile(["QuitPre"], "Xtestout")
    au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")
    quit
  [CODE]

  if RunVim([], after, '')
    call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout'))
  endif
  call delete('Xtestout')

  let after =<< trim [CODE]
    au QuitPre * call writefile(["QuitPre"], "Xtestout")
    au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")
    help
    wincmd w
    quit
  [CODE]

  if RunVim([], after, '')
    call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout'))
  endif
  call delete('Xtestout')

  let after =<< trim [CODE]
    au QuitPre * call writefile(["QuitPre"], "Xtestout")
    au ExitPre * call writefile(["ExitPre"], "Xtestout", "a")
    split
    new
    qall
  [CODE]

  if RunVim([], after, '')
    call assert_equal(['QuitPre', 'ExitPre'], readfile('Xtestout'))
  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")
    augroup nasty
      au ExitPre * split
    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
  [CODE]

  if RunVim([], after, '')
    call assert_equal(['QuitPre', 'ExitPre', 'QuitPre', 'ExitPre'],
	  \ readfile('Xtestout'))
  endif
  call delete('Xtestout')
endfunc