]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1971: Crash when buffer gets deleted inside charconvert during save v9.1.1971
authorglepnir <glephunter@gmail.com>
Thu, 11 Dec 2025 19:45:09 +0000 (20:45 +0100)
committerChristian Brabandt <cb@256bit.org>
Thu, 11 Dec 2025 19:48:43 +0000 (20:48 +0100)
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>
src/buffer.c
src/testdir/test_buffer.vim
src/version.c

index 90104cf0db785ca257b75344cfc04469b40380cb..0ed61a703265524327b2e1a5e3c27827c9766ab9 100644 (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;
index 1ffa7ae879afee18f1b79e652470852c4c8a8a7f..d688a8671e801d7312d26ec60910ed20dd0536ea 100644 (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()
index 2e806c33c16f9e4d5dbbb5627369b4228fef5bea..922242d91175df3c6066320bc9f175a7c65cbb8f 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1971,
 /**/
     1970,
 /**/