comparison src/buffer.c @ 25885:7c640ad754fb v8.2.3476

patch 8.2.3476: renaming a buffer on startup may cause using freed memory Commit: https://github.com/vim/vim/commit/d3710cf01ef6ab1b2f233866ff01dab76686f642 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Oct 4 23:13:13 2021 +0100 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 https://github.com/vim/vim/issues/8955)
author Bram Moolenaar <Bram@vim.org>
date Tue, 05 Oct 2021 00:15:04 +0200
parents 336e2d9924e6
children a63676a1da2b
comparison
equal deleted inserted replaced
25884:25fbd356bb09 25885:7c640ad754fb
3397 #else 3397 #else
3398 obuf = buflist_findname(ffname); 3398 obuf = buflist_findname(ffname);
3399 #endif 3399 #endif
3400 if (obuf != NULL && obuf != buf) 3400 if (obuf != NULL && obuf != buf)
3401 { 3401 {
3402 if (obuf->b_ml.ml_mfp != NULL) // it's loaded, fail 3402 win_T *win;
3403 tabpage_T *tab;
3404 int in_use = FALSE;
3405
3406 // during startup a window may use a buffer that is not loaded yet
3407 FOR_ALL_TAB_WINDOWS(tab, win)
3408 if (win->w_buffer == obuf)
3409 in_use = TRUE;
3410
3411 // it's loaded or used in a window, fail
3412 if (obuf->b_ml.ml_mfp != NULL || in_use)
3403 { 3413 {
3404 if (message) 3414 if (message)
3405 emsg(_("E95: Buffer with this name already exists")); 3415 emsg(_("E95: Buffer with this name already exists"));
3406 vim_free(ffname); 3416 vim_free(ffname);
3407 return FAIL; 3417 return FAIL;