0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.3476: renaming a buffer on startup may cause using freed memory

Problem:    Renaming a buffer on startup may cause using freed memory.
Solution:   Check if the buffer is used in a window. (closes #8955)
This commit is contained in:
Bram Moolenaar
2021-10-04 23:13:13 +01:00
parent 08d7b1c828
commit d3710cf01e
3 changed files with 27 additions and 1 deletions

View File

@@ -3399,7 +3399,17 @@ setfname(
#endif
if (obuf != NULL && obuf != buf)
{
if (obuf->b_ml.ml_mfp != NULL) // it's loaded, fail
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"));