0
0
mirror of https://github.com/vim/vim.git synced 2025-09-26 04:04:07 -04:00

patch 8.2.3560: using freed memory with lambda

Problem:    Using freed memory with lambda.
Solution:   Do not free lines early, keep them until the expression is
            finished.
This commit is contained in:
Bram Moolenaar
2021-10-23 13:32:30 +01:00
parent ee56f3f119
commit 844fb64a60
8 changed files with 63 additions and 20 deletions

View File

@@ -1177,12 +1177,17 @@ lambda_function_body(
if (cmdline != NULL)
{
garray_T *tfgap = &evalarg->eval_tofree_ga;
// Something comes after the "}".
*arg = eap.nextcmd;
// "arg" points into cmdline, need to keep the line and free it later.
vim_free(evalarg->eval_tofree_cmdline);
evalarg->eval_tofree_cmdline = cmdline;
if (ga_grow(tfgap, 1) == OK)
{
((char_u **)(tfgap->ga_data))[tfgap->ga_len++] = cmdline;
evalarg->eval_using_cmdline = TRUE;
}
}
else
*arg = (char_u *)"";
@@ -4867,7 +4872,7 @@ ex_return(exarg_T *eap)
return;
}
CLEAR_FIELD(evalarg);
init_evalarg(&evalarg);
evalarg.eval_flags = eap->skip ? 0 : EVAL_EVALUATE;
if (eap->skip)