Patch 8.2.2636 (after 8.2.2635)
Problem: Memory leak when compiling inline function.
Solution: Free the prefetched line.
Files: src/userfunc.c, src/vim9compile.c, src/structs.h, src/globals.h,
src/eval.c
*** ../vim-8.2.2635/src/userfunc.c 2021-03-21 20:53:24.926400996 +0100
--- src/userfunc.c 2021-03-21 22:01:11.290063632 +0100
***************
*** 970,986 ****
ga_init2(&newlines, (int)sizeof(char_u *), 10);
if (get_function_body(&eap, &newlines, NULL, &line_to_free) == FAIL)
goto erret;
if (cmdline != NULL)
{
// Something comes after the "}".
*arg = eap.nextcmd;
! if (evalarg->eval_cctx == NULL)
! {
! // Need to keep the line and free it/ later.
! vim_free(evalarg->eval_tofree_lambda);
! evalarg->eval_tofree_lambda = cmdline;
! }
}
else
*arg = (char_u *)"";
--- 970,987 ----
ga_init2(&newlines, (int)sizeof(char_u *), 10);
if (get_function_body(&eap, &newlines, NULL, &line_to_free) == FAIL)
+ {
+ vim_free(cmdline);
goto erret;
+ }
if (cmdline != NULL)
{
// 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;
}
else
*arg = (char_u *)"";
*** ../vim-8.2.2635/src/vim9compile.c 2021-03-21 20:53:24.926400996 +0100
--- src/vim9compile.c 2021-03-21 22:01:37.662021671 +0100
***************
*** 3202,3207 ****
--- 3202,3217 ----
// Compile the function into instructions.
compile_def_function(ufunc, TRUE, PROFILING(ufunc), cctx);
+ // evalarg.eval_tofree_cmdline may have a copy of the last line and "*arg"
+ // points into it. Point to the original line to avoid a dangling pointer.
+ if (evalarg.eval_tofree_cmdline != NULL)
+ {
+ size_t off = *arg - evalarg.eval_tofree_cmdline;
+
+ *arg = ((char_u **)cctx->ctx_ufunc->uf_lines.ga_data)[cctx->ctx_lnum]
+ + off;
+ }
+
clear_evalarg(&evalarg, NULL);
if (ufunc->uf_def_status == UF_COMPILED)
*** ../vim-8.2.2635/src/structs.h 2021-02-15 20:37:58.457374538 +0100
--- src/structs.h 2021-03-21 22:02:17.297957386 +0100
***************
*** 1882,1887 ****
--- 1882,1890 ----
// pointer to the last line obtained with getsourceline()
char_u *eval_tofree;
+ // pointer to the last line of an inline function
+ char_u *eval_tofree_cmdline;
+
// pointer to the lines concatenated for a lambda.
char_u *eval_tofree_lambda;
} evalarg_T;
*** ../vim-8.2.2635/src/globals.h 2021-03-10 21:26:34.152867581 +0100
--- src/globals.h 2021-03-21 22:03:46.049808295 +0100
***************
*** 1898,1904 ****
// Passed to an eval() function to enable evaluation.
EXTERN evalarg_T EVALARG_EVALUATE
# ifdef DO_INIT
! = {EVAL_EVALUATE, 0, NULL, NULL, NULL, {0, 0, 0, 0, NULL}, NULL, NULL}
# endif
;
#endif
--- 1898,1905 ----
// Passed to an eval() function to enable evaluation.
EXTERN evalarg_T EVALARG_EVALUATE
# ifdef DO_INIT
! = {EVAL_EVALUATE, 0, NULL, NULL, NULL, {0, 0, 0, 0, NULL},
! NULL, NULL, NULL}
# endif
;
#endif
*** ../vim-8.2.2635/src/eval.c 2021-03-20 13:29:35.255669769 +0100
--- src/eval.c 2021-03-21 22:09:02.549232368 +0100
***************
*** 2179,2186 ****
evalarg->eval_tofree = NULL;
}
! vim_free(evalarg->eval_tofree_lambda);
! evalarg->eval_tofree_lambda = NULL;
}
}
--- 2179,2186 ----
evalarg->eval_tofree = NULL;
}
! VIM_CLEAR(evalarg->eval_tofree_cmdline);
! VIM_CLEAR(evalarg->eval_tofree_lambda);
}
}
*** ../vim-8.2.2635/src/version.c 2021-03-21 20:53:24.930400991 +0100
--- src/version.c 2021-03-21 22:02:30.689935315 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2636,
/**/
--
10e12 microphone == 1 megaphone
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language --
http://www.Zimbu.org ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///