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: #18901

Signed-off-by: glepnir <glephunter@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
glepnir
2025-12-11 20:45:09 +01:00
committed by Christian Brabandt
parent fa3bdc2501
commit fe1c57cd2c
3 changed files with 13 additions and 0 deletions

View File

@@ -516,6 +516,10 @@ can_unload_buffer(buf_T *buf)
break;
}
}
// Don't unload the buffer while it's still being saved
if (can_unload && buf->b_saving)
can_unload = FALSE;
if (!can_unload)
{
char_u *fname = buf->b_fname != NULL ? buf->b_fname : buf->b_ffname;

View File

@@ -226,6 +226,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()

View File

@@ -729,6 +729,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1971,
/**/
1970,
/**/