To: vim_dev@googlegroups.com Subject: Patch 9.0.0614 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0614 Problem: SpellFileMissing autocmd may delete buffer. Solution: Disallow deleting the current buffer to avoid using freed memory. Files: src/spell.c, src/buffer.c, src/testdir/test_autocmd.vim *** ../vim-9.0.0613/src/spell.c 2022-09-25 20:58:08.801019377 +0100 --- src/spell.c 2022-09-28 11:32:59.041364257 +0100 *************** *** 1568,1573 **** --- 1568,1577 ---- sl.sl_slang = NULL; sl.sl_nobreak = FALSE; + // Disallow deleting the current buffer. Autocommands can do weird things + // and cause "lang" to be freed. + ++curbuf->b_locked; + // We may retry when no spell file is found for the language, an // autocommand may load it then. for (round = 1; round <= 2; ++round) *************** *** 1621,1626 **** --- 1625,1632 ---- STRCPY(fname_enc + STRLEN(fname_enc) - 3, "add.spl"); do_in_runtimepath(fname_enc, DIP_ALL, spell_load_cb, &sl); } + + --curbuf->b_locked; } /* *** ../vim-9.0.0613/src/buffer.c 2022-08-26 12:58:14.517930190 +0100 --- src/buffer.c 2022-09-28 11:44:43.641287537 +0100 *************** *** 468,474 **** } } if (!can_unload) ! semsg(_(e_attempt_to_delete_buffer_that_is_in_use_str), buf->b_fname); return can_unload; } --- 468,479 ---- } } if (!can_unload) ! { ! char_u *fname = buf->b_fname != NULL ? buf->b_fname : buf->b_ffname; ! ! semsg(_(e_attempt_to_delete_buffer_that_is_in_use_str), ! fname != NULL ? fname : (char_u *)"[No Name]"); ! } return can_unload; } *** ../vim-9.0.0613/src/testdir/test_autocmd.vim 2022-09-23 21:26:36.293344160 +0100 --- src/testdir/test_autocmd.vim 2022-09-28 11:45:13.861271559 +0100 *************** *** 2880,2885 **** --- 2880,2895 ---- setglobal spellfile= endfunc + " this was wiping out the current buffer and using freed memory + func Test_SpellFileMissing_bwipe() + next 0 + au SpellFileMissing 0 bwipe + call assert_fails('set spell spelllang=0', 'E937:') + + au! SpellFileMissing + bwipe + endfunc + " Test closing a window or editing another buffer from a FileChangedRO handler " in a readonly buffer func Test_FileChangedRO_winclose() *** ../vim-9.0.0613/src/version.c 2022-09-28 10:45:11.709718298 +0100 --- src/version.c 2022-09-28 11:27:43.665025485 +0100 *************** *** 701,702 **** --- 701,704 ---- { /* Add new patch number below this line */ + /**/ + 614, /**/ -- hundred-and-one symptoms of being an internet addict: 203. You're an active member of more than 20 newsgroups. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///