comparison src/vim9execute.c @ 19726:ad37a198a708 v8.2.0419

patch 8.2.0419: various memory leaks in Vim9 script code Commit: https://github.com/vim/vim/commit/20431c9dbb592ebe0666bf042af7d2b373107372 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Mar 20 18:39:46 2020 +0100 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 https://github.com/vim/vim/issues/5814)
author Bram Moolenaar <Bram@vim.org>
date Fri, 20 Mar 2020 18:45:04 +0100
parents d202122a4963
children 4174c4da6ff7
comparison
equal deleted inserted replaced
19725:700b7d225e02 19726:ad37a198a708
281 { 281 {
282 // The function has been compiled, can call it quickly. For a function 282 // The function has been compiled, can call it quickly. For a function
283 // that was defined later: we can call it directly next time. 283 // that was defined later: we can call it directly next time.
284 if (iptr != NULL) 284 if (iptr != NULL)
285 { 285 {
286 delete_instr(iptr);
286 iptr->isn_type = ISN_DCALL; 287 iptr->isn_type = ISN_DCALL;
287 iptr->isn_arg.dfunc.cdf_idx = ufunc->uf_dfunc_idx; 288 iptr->isn_arg.dfunc.cdf_idx = ufunc->uf_dfunc_idx;
288 iptr->isn_arg.dfunc.cdf_argcount = argcount; 289 iptr->isn_arg.dfunc.cdf_argcount = argcount;
289 } 290 }
290 return call_dfunc(ufunc->uf_dfunc_idx, argcount, ectx); 291 return call_dfunc(ufunc->uf_dfunc_idx, argcount, ectx);
478 init_instr_idx(ufunc, argc, &ectx); 479 init_instr_idx(ufunc, argc, &ectx);
479 480
480 for (;;) 481 for (;;)
481 { 482 {
482 isn_T *iptr; 483 isn_T *iptr;
483 trycmd_T *trycmd = NULL; 484
485 veryfast_breakcheck();
486 if (got_int)
487 {
488 // Turn CTRL-C into an exception.
489 got_int = FALSE;
490 if (throw_exception("Vim:Interrupt", ET_INTERRUPT, NULL) != FAIL)
491 goto failed;
492 did_throw = TRUE;
493 }
484 494
485 if (did_throw && !ectx.ec_in_catch) 495 if (did_throw && !ectx.ec_in_catch)
486 { 496 {
487 garray_T *trystack = &ectx.ec_trystack; 497 garray_T *trystack = &ectx.ec_trystack;
498 trycmd_T *trycmd = NULL;
488 499
489 // An exception jumps to the first catch, finally, or returns from 500 // An exception jumps to the first catch, finally, or returns from
490 // the current function. 501 // the current function.
491 if (trystack->ga_len > 0) 502 if (trystack->ga_len > 0)
492 trycmd = ((trycmd_T *)trystack->ga_data) + trystack->ga_len - 1; 503 trycmd = ((trycmd_T *)trystack->ga_data) + trystack->ga_len - 1;
780 break; 791 break;
781 792
782 // store $ENV 793 // store $ENV
783 case ISN_STOREENV: 794 case ISN_STOREENV:
784 --ectx.ec_stack.ga_len; 795 --ectx.ec_stack.ga_len;
785 vim_setenv_ext(iptr->isn_arg.string, 796 tv = STACK_TV_BOT(0);
786 tv_get_string(STACK_TV_BOT(0))); 797 vim_setenv_ext(iptr->isn_arg.string, tv_get_string(tv));
798 clear_tv(tv);
787 break; 799 break;
788 800
789 // store @r 801 // store @r
790 case ISN_STOREREG: 802 case ISN_STOREREG:
791 { 803 {
1036 1048
1037 // return from a :def function call 1049 // return from a :def function call
1038 case ISN_RETURN: 1050 case ISN_RETURN:
1039 { 1051 {
1040 garray_T *trystack = &ectx.ec_trystack; 1052 garray_T *trystack = &ectx.ec_trystack;
1053 trycmd_T *trycmd = NULL;
1041 1054
1042 if (trystack->ga_len > 0) 1055 if (trystack->ga_len > 0)
1043 trycmd = ((trycmd_T *)trystack->ga_data) 1056 trycmd = ((trycmd_T *)trystack->ga_data)
1044 + trystack->ga_len - 1; 1057 + trystack->ga_len - 1;
1045 if (trycmd != NULL && trycmd->tcd_frame == ectx.ec_frame 1058 if (trycmd != NULL && trycmd->tcd_frame == ectx.ec_frame
1144 break; 1157 break;
1145 1158
1146 // start of ":try" block 1159 // start of ":try" block
1147 case ISN_TRY: 1160 case ISN_TRY:
1148 { 1161 {
1162 trycmd_T *trycmd = NULL;
1163
1149 if (ga_grow(&ectx.ec_trystack, 1) == FAIL) 1164 if (ga_grow(&ectx.ec_trystack, 1) == FAIL)
1150 goto failed; 1165 goto failed;
1151 trycmd = ((trycmd_T *)ectx.ec_trystack.ga_data) 1166 trycmd = ((trycmd_T *)ectx.ec_trystack.ga_data)
1152 + ectx.ec_trystack.ga_len; 1167 + ectx.ec_trystack.ga_len;
1153 ++ectx.ec_trystack.ga_len; 1168 ++ectx.ec_trystack.ga_len;
1178 { 1193 {
1179 garray_T *trystack = &ectx.ec_trystack; 1194 garray_T *trystack = &ectx.ec_trystack;
1180 1195
1181 if (trystack->ga_len > 0) 1196 if (trystack->ga_len > 0)
1182 { 1197 {
1183 trycmd = ((trycmd_T *)trystack->ga_data) 1198 trycmd_T *trycmd = ((trycmd_T *)trystack->ga_data)
1184 + trystack->ga_len - 1; 1199 + trystack->ga_len - 1;
1185 trycmd->tcd_caught = TRUE; 1200 trycmd->tcd_caught = TRUE;
1186 } 1201 }
1187 did_emsg = got_int = did_throw = FALSE; 1202 did_emsg = got_int = did_throw = FALSE;
1188 catch_exception(current_exception); 1203 catch_exception(current_exception);
1194 { 1209 {
1195 garray_T *trystack = &ectx.ec_trystack; 1210 garray_T *trystack = &ectx.ec_trystack;
1196 1211
1197 if (trystack->ga_len > 0) 1212 if (trystack->ga_len > 0)
1198 { 1213 {
1214 trycmd_T *trycmd = NULL;
1215
1199 --trystack->ga_len; 1216 --trystack->ga_len;
1200 --trylevel; 1217 --trylevel;
1201 trycmd = ((trycmd_T *)trystack->ga_data) 1218 trycmd = ((trycmd_T *)trystack->ga_data)
1202 + trystack->ga_len; 1219 + trystack->ga_len;
1203 if (trycmd->tcd_caught && current_exception != NULL) 1220 if (trycmd->tcd_caught && current_exception != NULL)
1675 func_return(&ectx); 1692 func_return(&ectx);
1676 1693
1677 for (idx = 0; idx < ectx.ec_stack.ga_len; ++idx) 1694 for (idx = 0; idx < ectx.ec_stack.ga_len; ++idx)
1678 clear_tv(STACK_TV(idx)); 1695 clear_tv(STACK_TV(idx));
1679 vim_free(ectx.ec_stack.ga_data); 1696 vim_free(ectx.ec_stack.ga_data);
1697 vim_free(ectx.ec_trystack.ga_data);
1680 return ret; 1698 return ret;
1681 } 1699 }
1682 1700
1683 /* 1701 /*
1684 * ":dissassemble". 1702 * ":dissassemble".