vim-patch:9.1.1971: Crash when buffer gets deleted inside charconvert during save

Problem:  Crash when buffer gets deleted inside charconvert during save
Solution: Check for `b_saving` inside `can_unload_buffer()`, so we don’t try to
          unload a buffer while it’s still being saved (glepnir).

closes: vim/vim#18901

fe1c57cd2c

Co-authored-by: glepnir <glephunter@gmail.com>
This commit is contained in:
zeertzjq
2025-12-12 08:54:18 +08:00
parent 2b02dfa020
commit e9da68effe
2 changed files with 12 additions and 0 deletions

View File

@@ -479,6 +479,11 @@ static bool can_unload_buffer(buf_T *buf)
}
}
}
// Don't unload the buffer while it's still being saved
if (can_unload && buf->b_saving) {
can_unload = false;
}
if (!can_unload) {
char *fname = buf->b_fname != NULL ? buf->b_fname : buf->b_ffname;
semsg(_(e_attempt_to_delete_buffer_that_is_in_use_str),

View File

@@ -228,6 +228,13 @@ func Test_buffer_error()
%bwipe
endfunc
func Test_bwipe_during_save()
set charconvert=execute('%bw!')
call assert_fails('write ++enc=lmao boom', 'E937:')
%bwipe
endfunc
" Test for the status messages displayed when unloading, deleting or wiping
" out buffers
func Test_buffer_statusmsg()