diff options
author | Bram Moolenaar <Bram@vim.org> | 2010-06-06 15:21:10 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2010-06-06 15:21:10 +0200 |
commit | 1950c3529b16acd21ee5770b422d633f24d192a3 (patch) | |
tree | 0710904eec725a784f02093d972dde0fe6c41329 /src/syntax.c | |
parent | 56be950094e10e68da1f901ba971c5f3e9821685 (diff) | |
download | vim-git-1950c3529b16acd21ee5770b422d633f24d192a3.tar.gz |
Fixed memory leak in ":ownsyntax".
Diffstat (limited to 'src/syntax.c')
-rw-r--r-- | src/syntax.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/syntax.c b/src/syntax.c index 370bc761b..2b70c6d45 100644 --- a/src/syntax.c +++ b/src/syntax.c @@ -3537,8 +3537,7 @@ syn_cmd_clear(eap, syncing) syntax_clear(curwin->w_s); if (curwin->w_s == &curwin->w_buffer->b_s) do_unlet((char_u *)"b:current_syntax", TRUE); - else - do_unlet((char_u *)"w:current_syntax", TRUE); + do_unlet((char_u *)"w:current_syntax", TRUE); } } @@ -6157,6 +6156,9 @@ ex_syntax(eap) ex_ownsyntax(eap) exarg_T *eap; { + char_u *old_value; + char_u *new_value; + if (curwin->w_s == &curwin->w_buffer->b_s) { curwin->w_s = (synblock_T *)alloc(sizeof(synblock_T)); @@ -6170,7 +6172,26 @@ ex_ownsyntax(eap) clear_string_option(&curwin->w_s->b_p_spl); #endif } + + /* save value of b:current_syntax */ + old_value = get_var_value((char_u *)"b:current_syntax"); + if (old_value != NULL) + old_value = vim_strsave(old_value); + + /* Apply the "syntax" autocommand event, this finds and loads the syntax + * file. */ apply_autocmds(EVENT_SYNTAX, eap->arg, curbuf->b_fname, TRUE, curbuf); + + /* move value of b:current_syntax to w:current_syntax */ + new_value = get_var_value((char_u *)"b:current_syntax"); + set_internal_string_var((char_u *)"w:current_syntax", new_value); + + /* restore value of b:current_syntax */ + if (old_value != NULL) + { + set_internal_string_var((char_u *)"b:current_syntax", old_value); + vim_free(old_value); + } } int |