mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 9.0.0554: using freed memory when command follows lambda
Problem: Using freed memory when command follows lambda. Solution: Don't free what is still in use. (closes #11201)
This commit is contained in:
19
src/eval.c
19
src/eval.c
@@ -382,15 +382,26 @@ clear_evalarg(evalarg_T *evalarg, exarg_T *eap)
|
|||||||
{
|
{
|
||||||
if (evalarg != NULL)
|
if (evalarg != NULL)
|
||||||
{
|
{
|
||||||
if (evalarg->eval_tofree != NULL)
|
garray_T *etga = &evalarg->eval_tofree_ga;
|
||||||
|
|
||||||
|
if (evalarg->eval_tofree != NULL || evalarg->eval_using_cmdline)
|
||||||
{
|
{
|
||||||
if (eap != NULL)
|
if (eap != NULL)
|
||||||
{
|
{
|
||||||
// We may need to keep the original command line, e.g. for
|
// We may need to keep the original command line, e.g. for
|
||||||
// ":let" it has the variable names. But we may also need the
|
// ":let" it has the variable names. But we may also need
|
||||||
// new one, "nextcmd" points into it. Keep both.
|
// the new one, "nextcmd" points into it. Keep both.
|
||||||
vim_free(eap->cmdline_tofree);
|
vim_free(eap->cmdline_tofree);
|
||||||
eap->cmdline_tofree = *eap->cmdlinep;
|
eap->cmdline_tofree = *eap->cmdlinep;
|
||||||
|
|
||||||
|
if (evalarg->eval_using_cmdline && etga->ga_len > 0)
|
||||||
|
{
|
||||||
|
// "nextcmd" points into the last line in eval_tofree_ga,
|
||||||
|
// need to keep it around.
|
||||||
|
--etga->ga_len;
|
||||||
|
*eap->cmdlinep = ((char_u **)etga->ga_data)[etga->ga_len];
|
||||||
|
}
|
||||||
|
else
|
||||||
*eap->cmdlinep = evalarg->eval_tofree;
|
*eap->cmdlinep = evalarg->eval_tofree;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -398,7 +409,7 @@ clear_evalarg(evalarg_T *evalarg, exarg_T *eap)
|
|||||||
evalarg->eval_tofree = NULL;
|
evalarg->eval_tofree = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ga_clear_strings(&evalarg->eval_tofree_ga);
|
ga_clear_strings(etga);
|
||||||
VIM_CLEAR(evalarg->eval_tofree_lambda);
|
VIM_CLEAR(evalarg->eval_tofree_lambda);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1515,6 +1515,20 @@ def Test_lambda_invalid_block()
|
|||||||
v9.CheckDefAndScriptFailure(lines, 'E488: Trailing characters: | echo')
|
v9.CheckDefAndScriptFailure(lines, 'E488: Trailing characters: | echo')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_lambda_with_following_cmd()
|
||||||
|
var lines =<< trim END
|
||||||
|
set ts=2
|
||||||
|
var Lambda = () => {
|
||||||
|
set ts=4
|
||||||
|
} | set ts=3
|
||||||
|
assert_equal(3, &ts)
|
||||||
|
Lambda()
|
||||||
|
assert_equal(4, &ts)
|
||||||
|
END
|
||||||
|
v9.CheckDefAndScriptSuccess(lines)
|
||||||
|
set ts=8
|
||||||
|
enddef
|
||||||
|
|
||||||
def Test_pass_legacy_lambda_to_def_func()
|
def Test_pass_legacy_lambda_to_def_func()
|
||||||
var lines =<< trim END
|
var lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
@@ -699,6 +699,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 */
|
||||||
|
/**/
|
||||||
|
554,
|
||||||
/**/
|
/**/
|
||||||
553,
|
553,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -522,10 +522,12 @@ compile_load(
|
|||||||
{
|
{
|
||||||
type = lvar.lv_type;
|
type = lvar.lv_type;
|
||||||
idx = lvar.lv_idx;
|
idx = lvar.lv_idx;
|
||||||
|
if (lvar.lv_from_outer != 0)
|
||||||
|
{
|
||||||
|
gen_load_outer = lvar.lv_from_outer;
|
||||||
outer_loop_depth = lvar.lv_loop_depth;
|
outer_loop_depth = lvar.lv_loop_depth;
|
||||||
outer_loop_idx = lvar.lv_loop_idx;
|
outer_loop_idx = lvar.lv_loop_idx;
|
||||||
if (lvar.lv_from_outer != 0)
|
}
|
||||||
gen_load_outer = lvar.lv_from_outer;
|
|
||||||
else
|
else
|
||||||
gen_load = TRUE;
|
gen_load = TRUE;
|
||||||
}
|
}
|
||||||
@@ -1096,6 +1098,7 @@ compile_lambda(char_u **arg, cctx_T *cctx)
|
|||||||
|
|
||||||
*arg = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum]
|
*arg = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum]
|
||||||
+ off;
|
+ off;
|
||||||
|
evalarg.eval_using_cmdline = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_evalarg(&evalarg, NULL);
|
clear_evalarg(&evalarg, NULL);
|
||||||
|
Reference in New Issue
Block a user