comparison src/vim9compile.c @ 22326:fb69b43d73f3 v8.2.1712

patch 8.2.1712: Vim9: leaking memory when calling a lambda Commit: https://github.com/vim/vim/commit/a05e524f3aa8eadc2dbd0ad8ff6db9407ac7ac7e Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 19 18:19:19 2020 +0200 patch 8.2.1712: Vim9: leaking memory when calling a lambda Problem: Vim9: leaking memory when calling a lambda. Solution: Decrement function reference from ISN_DCALL.
author Bram Moolenaar <Bram@vim.org>
date Sat, 19 Sep 2020 18:30:04 +0200
parents a4ed0de125d9
children fc3350a38389
comparison
equal deleted inserted replaced
22325:543812d79fae 22326:fb69b43d73f3
1450 1450
1451 if ((isn = generate_instr(cctx, 1451 if ((isn = generate_instr(cctx,
1452 ufunc->uf_def_status != UF_NOT_COMPILED ? ISN_DCALL 1452 ufunc->uf_def_status != UF_NOT_COMPILED ? ISN_DCALL
1453 : ISN_UCALL)) == NULL) 1453 : ISN_UCALL)) == NULL)
1454 return FAIL; 1454 return FAIL;
1455 if (ufunc->uf_def_status != UF_NOT_COMPILED) 1455 if (isn->isn_type == ISN_DCALL)
1456 { 1456 {
1457 isn->isn_arg.dfunc.cdf_idx = ufunc->uf_dfunc_idx; 1457 isn->isn_arg.dfunc.cdf_idx = ufunc->uf_dfunc_idx;
1458 isn->isn_arg.dfunc.cdf_argcount = argcount; 1458 isn->isn_arg.dfunc.cdf_argcount = argcount;
1459 } 1459 }
1460 else 1460 else
2632 ufunc = rettv.vval.v_partial->pt_func; 2632 ufunc = rettv.vval.v_partial->pt_func;
2633 ++ufunc->uf_refcount; 2633 ++ufunc->uf_refcount;
2634 clear_tv(&rettv); 2634 clear_tv(&rettv);
2635 ga_init2(&ufunc->uf_type_list, sizeof(type_T *), 10); 2635 ga_init2(&ufunc->uf_type_list, sizeof(type_T *), 10);
2636 2636
2637 // The function will have one line: "return {expr}". 2637 // The function will have one line: "return {expr}". Compile it into
2638 // Compile it into instructions. 2638 // instructions so that we get any errors right now.
2639 compile_def_function(ufunc, TRUE, cctx); 2639 compile_def_function(ufunc, TRUE, cctx);
2640 2640
2641 // compile the arguments 2641 // compile the arguments
2642 *arg = skipwhite(*arg + 1); 2642 *arg = skipwhite(*arg + 1);
2643 if (compile_arguments(arg, cctx, &argcount) == OK) 2643 if (compile_arguments(arg, cctx, &argcount) == OK)
7283 7283
7284 case ISN_FUNCREF: 7284 case ISN_FUNCREF:
7285 { 7285 {
7286 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) 7286 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
7287 + isn->isn_arg.funcref.fr_func; 7287 + isn->isn_arg.funcref.fr_func;
7288 func_ptr_unref(dfunc->df_ufunc); 7288
7289 if (func_name_refcount(dfunc->df_ufunc->uf_name))
7290 func_ptr_unref(dfunc->df_ufunc);
7291 }
7292 break;
7293
7294 case ISN_DCALL:
7295 {
7296 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
7297 + isn->isn_arg.dfunc.cdf_idx;
7298
7299 if (func_name_refcount(dfunc->df_ufunc->uf_name))
7300 func_ptr_unref(dfunc->df_ufunc);
7289 } 7301 }
7290 break; 7302 break;
7291 7303
7292 case ISN_NEWFUNC: 7304 case ISN_NEWFUNC:
7293 { 7305 {
7331 case ISN_COMPARELIST: 7343 case ISN_COMPARELIST:
7332 case ISN_COMPARENR: 7344 case ISN_COMPARENR:
7333 case ISN_COMPARESPECIAL: 7345 case ISN_COMPARESPECIAL:
7334 case ISN_COMPARESTRING: 7346 case ISN_COMPARESTRING:
7335 case ISN_CONCAT: 7347 case ISN_CONCAT:
7336 case ISN_DCALL:
7337 case ISN_DROP: 7348 case ISN_DROP:
7338 case ISN_ECHO: 7349 case ISN_ECHO:
7339 case ISN_ECHOERR: 7350 case ISN_ECHOERR:
7340 case ISN_ECHOMSG: 7351 case ISN_ECHOMSG:
7341 case ISN_ENDTRY: 7352 case ISN_ENDTRY: