1
0
forked from aniani/vim

patch 8.2.3711: Vim9: memory leak when compiling :elseif fails

Problem:    Vim9: memory leak when compiling :elseif fails.
Solution:   Cleanup ppconst.
This commit is contained in:
Bram Moolenaar
2021-12-01 10:10:22 +00:00
parent 3d2e031d4f
commit 56a8ffdb6e
3 changed files with 17 additions and 2 deletions

View File

@@ -301,12 +301,21 @@ def Test_condition_types()
CheckDefAndScriptFailure(lines, 'E1135:', 3) CheckDefAndScriptFailure(lines, 'E1135:', 3)
lines =<< trim END lines =<< trim END
g:cond = 0
if g:cond
elseif 'text' garbage
endif
END
CheckDefAndScriptFailure(lines, 'E488:', 3)
lines =<< trim END
g:cond = 0
if g:cond if g:cond
elseif [1] elseif [1]
endif endif
END END
CheckDefFailure(lines, 'E1012:', 2) CheckDefFailure(lines, 'E1012:', 3)
CheckScriptFailure(['vim9script'] + lines, 'E745:', 3) CheckScriptFailure(['vim9script'] + lines, 'E745:', 4)
lines =<< trim END lines =<< trim END
g:cond = 'text' g:cond = 'text'

View File

@@ -753,6 +753,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
3711,
/**/ /**/
3710, 3710,
/**/ /**/

View File

@@ -7888,6 +7888,7 @@ compile_elseif(char_u *arg, cctx_T *cctx)
cctx->ctx_skip = save_skip; cctx->ctx_skip = save_skip;
if (!ends_excmd2(arg, skipwhite(p))) if (!ends_excmd2(arg, skipwhite(p)))
{ {
clear_ppconst(&ppconst);
semsg(_(e_trailing_arg), p); semsg(_(e_trailing_arg), p);
return NULL; return NULL;
} }
@@ -7901,7 +7902,10 @@ compile_elseif(char_u *arg, cctx_T *cctx)
// The expression result is a constant. // The expression result is a constant.
v = tv_get_bool_chk(&ppconst.pp_tv[0], &error); v = tv_get_bool_chk(&ppconst.pp_tv[0], &error);
if (error) if (error)
{
clear_ppconst(&ppconst);
return NULL; return NULL;
}
cctx->ctx_skip = v ? SKIP_NOT : SKIP_YES; cctx->ctx_skip = v ? SKIP_NOT : SKIP_YES;
clear_ppconst(&ppconst); clear_ppconst(&ppconst);
scope->se_u.se_if.is_if_label = -1; scope->se_u.se_if.is_if_label = -1;