summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-06-17 17:32:58 +0200
committerBram Moolenaar <Bram@vim.org>2018-06-17 17:32:58 +0200
commitc3ffc9b8d3015dc5280b297b4e3deb4f34944bd4 (patch)
tree5d46d2da282bc01f04e501d94818f48f5f5b01cb
parent0e6e179f55b85b9e82e74d3f993928d52f0f4d43 (diff)
downloadvim-git-c3ffc9b8d3015dc5280b297b4e3deb4f34944bd4.tar.gz
patch 8.1.0066: nasty autocommand causes using freed memoryv8.1.0066
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.
-rw-r--r--src/option.c18
-rw-r--r--src/version.c2
2 files changed, 14 insertions, 6 deletions
diff --git a/src/option.c b/src/option.c
index 23560798a..2ecdcea64 100644
--- a/src/option.c
+++ b/src/option.c
@@ -6029,7 +6029,7 @@ did_set_string_option(
/* set when changing an option that only requires a redraw in the GUI */
int redraw_gui_only = FALSE;
#endif
- int ft_changed = FALSE;
+ int value_changed = FALSE;
#if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
int did_swaptcap = FALSE;
#endif
@@ -7437,7 +7437,7 @@ did_set_string_option(
if (!valid_filetype(*varp))
errmsg = e_invarg;
else
- ft_changed = STRCMP(oldval, *varp) != 0;
+ value_changed = STRCMP(oldval, *varp) != 0;
}
#ifdef FEAT_SYN_HL
@@ -7445,6 +7445,8 @@ did_set_string_option(
{
if (!valid_filetype(*varp))
errmsg = e_invarg;
+ else
+ value_changed = STRCMP(oldval, *varp) != 0;
}
#endif
@@ -7565,20 +7567,24 @@ did_set_string_option(
/* When 'syntax' is set, load the syntax of that name */
if (varp == &(curbuf->b_p_syn))
{
+ // Only pass TRUE for "force" when the value changed, to avoid
+ // endless recurrence. */
apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
- curbuf->b_fname, TRUE, curbuf);
+ curbuf->b_fname, value_changed, curbuf);
}
#endif
else if (varp == &(curbuf->b_p_ft))
{
/* 'filetype' is set, trigger the FileType autocommand.
* Skip this when called from a modeline and the filetype was
- * already set to this value. */
- if (!(opt_flags & OPT_MODELINE) || ft_changed)
+ * already set to this value.
+ * Only pass TRUE for "force" when the value changed, to avoid
+ * endless recurrence. */
+ if (!(opt_flags & OPT_MODELINE) || value_changed)
{
did_filetype = TRUE;
apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
- curbuf->b_fname, TRUE, curbuf);
+ curbuf->b_fname, value_changed, curbuf);
/* Just in case the old "curbuf" is now invalid. */
if (varp != &(curbuf->b_p_ft))
varp = NULL;
diff --git a/src/version.c b/src/version.c
index 192b6cd2a..d3c7316c9 100644
--- a/src/version.c
+++ b/src/version.c
@@ -762,6 +762,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 66,
+/**/
65,
/**/
64,