patch 9.0.0614: SpellFileMissing autocmd may delete buffer

Problem:    SpellFileMissing autocmd may delete buffer.
Solution:   Disallow deleting the current buffer to avoid using freed memory.
This commit is contained in:
Bram Moolenaar
2022-09-28 11:48:30 +01:00
parent caa1d19da1
commit ef976323e7
4 changed files with 24 additions and 1 deletions

View File

@ -1568,6 +1568,10 @@ spell_load_lang(char_u *lang)
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,6 +1625,8 @@ spell_load_lang(char_u *lang)
STRCPY(fname_enc + STRLEN(fname_enc) - 3, "add.spl");
do_in_runtimepath(fname_enc, DIP_ALL, spell_load_cb, &sl);
}
--curbuf->b_locked;
}
/*