comparison src/option.c @ 14097:db44cd9f8068 v8.1.0066

patch 8.1.0066: nasty autocommand causes using freed memory commit https://github.com/vim/vim/commit/c3ffc9b8d3015dc5280b297b4e3deb4f34944bd4 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 17 17:32:58 2018 +0200 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.
author Christian Brabandt <cb@256bit.org>
date Sun, 17 Jun 2018 17:45:05 +0200
parents 1d25a3e8e03c
children 1157f16150b3
comparison
equal deleted inserted replaced
14096:1aa1395acb86 14097:db44cd9f8068
6027 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED); 6027 long_u free_oldval = (options[opt_idx].flags & P_ALLOCED);
6028 #ifdef FEAT_GUI 6028 #ifdef FEAT_GUI
6029 /* set when changing an option that only requires a redraw in the GUI */ 6029 /* set when changing an option that only requires a redraw in the GUI */
6030 int redraw_gui_only = FALSE; 6030 int redraw_gui_only = FALSE;
6031 #endif 6031 #endif
6032 int ft_changed = FALSE; 6032 int value_changed = FALSE;
6033 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS) 6033 #if defined(FEAT_VTP) && defined(FEAT_TERMGUICOLORS)
6034 int did_swaptcap = FALSE; 6034 int did_swaptcap = FALSE;
6035 #endif 6035 #endif
6036 6036
6037 /* Get the global option to compare with, otherwise we would have to check 6037 /* Get the global option to compare with, otherwise we would have to check
7435 else if (gvarp == &p_ft) 7435 else if (gvarp == &p_ft)
7436 { 7436 {
7437 if (!valid_filetype(*varp)) 7437 if (!valid_filetype(*varp))
7438 errmsg = e_invarg; 7438 errmsg = e_invarg;
7439 else 7439 else
7440 ft_changed = STRCMP(oldval, *varp) != 0; 7440 value_changed = STRCMP(oldval, *varp) != 0;
7441 } 7441 }
7442 7442
7443 #ifdef FEAT_SYN_HL 7443 #ifdef FEAT_SYN_HL
7444 else if (gvarp == &p_syn) 7444 else if (gvarp == &p_syn)
7445 { 7445 {
7446 if (!valid_filetype(*varp)) 7446 if (!valid_filetype(*varp))
7447 errmsg = e_invarg; 7447 errmsg = e_invarg;
7448 else
7449 value_changed = STRCMP(oldval, *varp) != 0;
7448 } 7450 }
7449 #endif 7451 #endif
7450 7452
7451 #ifdef FEAT_TERMINAL 7453 #ifdef FEAT_TERMINAL
7452 /* 'termwinkey' */ 7454 /* 'termwinkey' */
7563 */ 7565 */
7564 #ifdef FEAT_SYN_HL 7566 #ifdef FEAT_SYN_HL
7565 /* When 'syntax' is set, load the syntax of that name */ 7567 /* When 'syntax' is set, load the syntax of that name */
7566 if (varp == &(curbuf->b_p_syn)) 7568 if (varp == &(curbuf->b_p_syn))
7567 { 7569 {
7570 // Only pass TRUE for "force" when the value changed, to avoid
7571 // endless recurrence. */
7568 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn, 7572 apply_autocmds(EVENT_SYNTAX, curbuf->b_p_syn,
7569 curbuf->b_fname, TRUE, curbuf); 7573 curbuf->b_fname, value_changed, curbuf);
7570 } 7574 }
7571 #endif 7575 #endif
7572 else if (varp == &(curbuf->b_p_ft)) 7576 else if (varp == &(curbuf->b_p_ft))
7573 { 7577 {
7574 /* 'filetype' is set, trigger the FileType autocommand. 7578 /* 'filetype' is set, trigger the FileType autocommand.
7575 * Skip this when called from a modeline and the filetype was 7579 * Skip this when called from a modeline and the filetype was
7576 * already set to this value. */ 7580 * already set to this value.
7577 if (!(opt_flags & OPT_MODELINE) || ft_changed) 7581 * Only pass TRUE for "force" when the value changed, to avoid
7582 * endless recurrence. */
7583 if (!(opt_flags & OPT_MODELINE) || value_changed)
7578 { 7584 {
7579 did_filetype = TRUE; 7585 did_filetype = TRUE;
7580 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft, 7586 apply_autocmds(EVENT_FILETYPE, curbuf->b_p_ft,
7581 curbuf->b_fname, TRUE, curbuf); 7587 curbuf->b_fname, value_changed, curbuf);
7582 /* Just in case the old "curbuf" is now invalid. */ 7588 /* Just in case the old "curbuf" is now invalid. */
7583 if (varp != &(curbuf->b_p_ft)) 7589 if (varp != &(curbuf->b_p_ft))
7584 varp = NULL; 7590 varp = NULL;
7585 } 7591 }
7586 } 7592 }