Skip to content

Commit c3ffc9b

Browse files
committed
patch 8.1.0066: nasty autocommand causes using freed memory
Problem: Nasty autocommand causes using freed memory. (Dominique Pelle) Solution: Do not force executing autocommands if the value of 'syntax' or 'filetype' did not change.
1 parent 0e6e179 commit c3ffc9b

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

src/option.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6029,7 +6029,7 @@ did_set_string_option(
60296029
/* set when changing an option that only requires a redraw in the GUI */
60306030
int redraw_gui_only = FALSE;
60316031
#endif
6032-
int ft_changed = FALSE;
6032+
int value_changed = FALSE;
60336033
#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
60346034
int did_swaptcap = FALSE;
60356035
#endif
@@ -7437,14 +7437,16 @@ did_set_string_option(
74377437
if (!valid_filetype(*varp))
74387438
errmsg = e_invarg;
74397439
else
7440-
ft_changed = STRCMP(oldval, *varp) != 0;
7440+
value_changed = STRCMP(oldval, *varp) != 0;
74417441
}
74427442

74437443
#ifdef FEAT_SYN_HL
74447444
else if (gvarp == &p_syn)
74457445
{
74467446
if (!valid_filetype(*varp))
74477447
errmsg = e_invarg;
7448+
else
7449+
value_changed = STRCMP(oldval, *varp) != 0;
74487450
}
74497451
#endif
74507452

@@ -7565,20 +7567,24 @@ did_set_string_option(
75657567
/* When 'syntax' is set, load the syntax of that name */
75667568
if (varp == &(curbuf->b_p_syn))
75677569
{
7570+
// Only pass TRUE for "force" when the value changed, to avoid
7571+
// endless recurrence. */
75687572
apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7569-
curbuf->b_fname, TRUE, curbuf);
7573+
curbuf->b_fname, value_changed, curbuf);
75707574
}
75717575
#endif
75727576
else if (varp == &(curbuf->b_p_ft))
75737577
{
75747578
/* 'filetype' is set, trigger the FileType autocommand.
75757579
* Skip this when called from a modeline and the filetype was
7576-
* already set to this value. */
7577-
if (!(opt_flags & OPT_MODELINE) || ft_changed)
7580+
* already set to this value.
7581+
* Only pass TRUE for "force" when the value changed, to avoid
7582+
* endless recurrence. */
7583+
if (!(opt_flags & OPT_MODELINE) || value_changed)
75787584
{
75797585
did_filetype = TRUE;
75807586
apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7581-
curbuf->b_fname, TRUE, curbuf);
7587+
curbuf->b_fname, value_changed, curbuf);
75827588
/* Just in case the old "curbuf" is now invalid. */
75837589
if (varp != &(curbuf->b_p_ft))
75847590
varp = NULL;

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
66,
764766
/**/
765767
65,
766768
/**/

0 commit comments

Comments
 (0)