Patch 8.2.3476
Problem: Renaming a buffer on startup may cause using freed memory.
Solution: Check if the buffer is used in a window. (closes #8955)
Files: src/buffer.c, src/testdir/test_startup.vim
*** ../vim-8.2.3475/src/buffer.c 2021-10-02 11:23:01.566500862 +0100
--- src/buffer.c 2021-10-04 23:12:53.566223883 +0100
***************
*** 3399,3405 ****
#endif
if (obuf != NULL && obuf != buf)
{
! if (obuf->b_ml.ml_mfp != NULL) // it's loaded, fail
{
if (message)
emsg(_("E95: Buffer with this name already exists"));
--- 3399,3415 ----
#endif
if (obuf != NULL && obuf != buf)
{
! win_T *win;
! tabpage_T *tab;
! int in_use = FALSE;
!
! // during startup a window may use a buffer that is not loaded yet
! FOR_ALL_TAB_WINDOWS(tab, win)
! if (win->w_buffer == obuf)
! in_use = TRUE;
!
! // it's loaded or used in a window, fail
! if (obuf->b_ml.ml_mfp != NULL || in_use)
{
if (message)
emsg(_("E95: Buffer with this name already exists"));
*** ../vim-8.2.3475/src/testdir/test_startup.vim 2021-09-09 19:45:30.258411566 +0100
--- src/testdir/test_startup.vim 2021-10-04 22:59:26.868223587 +0100
***************
*** 1296,1299 ****
--- 1296,1313 ----
call delete('Xresult')
endfunc
+ func Test_rename_buffer_on_startup()
+ let lines =<< trim END
+ call writefile(['done'], 'Xresult')
+ qa!
+ END
+ call writefile(lines, 'Xscript')
+ if RunVim([], [], "--clean -e -s --cmd 'file x|new|file x' --cmd 'so Xscript'")
+ call assert_equal(['done'], readfile('Xresult'))
+ endif
+ call delete('Xscript')
+ call delete('Xresult')
+ endfunc
+
+
" vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.3475/src/version.c 2021-10-04 22:17:32.778131139 +0100
--- src/version.c 2021-10-04 22:50:48.385742242 +0100
***************
*** 759,760 ****
--- 759,762 ----
{ /* Add new patch number below this line */
+ /**/
+ 3476,
/**/
--
hundred-and-one symptoms of being an internet addict:
95. Only communication in your household is through email.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///