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

Commit: 
https://github.com/vim/vim/commit/fe1c57cd2caa7de2ce23557646d6c62a9a1b4f92
Author: glepnir <[email protected]>
Date:   Thu Dec 11 20:45:09 2025 +0100

    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 <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/buffer.c b/src/buffer.c
index 90104cf0d..0ed61a703 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -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;
diff --git a/src/testdir/test_buffer.vim b/src/testdir/test_buffer.vim
index 1ffa7ae87..d688a8671 100644
--- a/src/testdir/test_buffer.vim
+++ b/src/testdir/test_buffer.vim
@@ -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()
diff --git a/src/version.c b/src/version.c
index 2e806c33c..922242d91 100644
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1971,
 /**/
     1970,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1vTmpY-00AFHh-DO%40256bit.org.

Raspunde prin e-mail lui