patch 8.2.0419: various memory leaks in Vim9 script code
Problem: Various memory leaks in Vim9 script code.
Solution: Fix the leaks. (Ozaki Kiichi, closes #5814)
diff --git a/src/vim9execute.c b/src/vim9execute.c
index 8c8bf88..33b6430 100644
--- a/src/vim9execute.c
+++ b/src/vim9execute.c
@@ -283,6 +283,7 @@
// that was defined later: we can call it directly next time.
if (iptr != NULL)
{
+ delete_instr(iptr);
iptr->isn_type = ISN_DCALL;
iptr->isn_arg.dfunc.cdf_idx = ufunc->uf_dfunc_idx;
iptr->isn_arg.dfunc.cdf_argcount = argcount;
@@ -480,11 +481,21 @@
for (;;)
{
isn_T *iptr;
- trycmd_T *trycmd = NULL;
+
+ veryfast_breakcheck();
+ if (got_int)
+ {
+ // Turn CTRL-C into an exception.
+ got_int = FALSE;
+ if (throw_exception("Vim:Interrupt", ET_INTERRUPT, NULL) != FAIL)
+ goto failed;
+ did_throw = TRUE;
+ }
if (did_throw && !ectx.ec_in_catch)
{
garray_T *trystack = &ectx.ec_trystack;
+ trycmd_T *trycmd = NULL;
// An exception jumps to the first catch, finally, or returns from
// the current function.
@@ -782,8 +793,9 @@
// store $ENV
case ISN_STOREENV:
--ectx.ec_stack.ga_len;
- vim_setenv_ext(iptr->isn_arg.string,
- tv_get_string(STACK_TV_BOT(0)));
+ tv = STACK_TV_BOT(0);
+ vim_setenv_ext(iptr->isn_arg.string, tv_get_string(tv));
+ clear_tv(tv);
break;
// store @r
@@ -1038,6 +1050,7 @@
case ISN_RETURN:
{
garray_T *trystack = &ectx.ec_trystack;
+ trycmd_T *trycmd = NULL;
if (trystack->ga_len > 0)
trycmd = ((trycmd_T *)trystack->ga_data)
@@ -1146,6 +1159,8 @@
// start of ":try" block
case ISN_TRY:
{
+ trycmd_T *trycmd = NULL;
+
if (ga_grow(&ectx.ec_trystack, 1) == FAIL)
goto failed;
trycmd = ((trycmd_T *)ectx.ec_trystack.ga_data)
@@ -1180,7 +1195,7 @@
if (trystack->ga_len > 0)
{
- trycmd = ((trycmd_T *)trystack->ga_data)
+ trycmd_T *trycmd = ((trycmd_T *)trystack->ga_data)
+ trystack->ga_len - 1;
trycmd->tcd_caught = TRUE;
}
@@ -1196,6 +1211,8 @@
if (trystack->ga_len > 0)
{
+ trycmd_T *trycmd = NULL;
+
--trystack->ga_len;
--trylevel;
trycmd = ((trycmd_T *)trystack->ga_data)
@@ -1677,6 +1694,7 @@
for (idx = 0; idx < ectx.ec_stack.ga_len; ++idx)
clear_tv(STACK_TV(idx));
vim_free(ectx.ec_stack.ga_data);
+ vim_free(ectx.ec_trystack.ga_data);
return ret;
}