]> granicus.if.org Git - vim/commitdiff
patch 8.2.0726: Vim9: leaking memory when calling not compiled :def function v8.2.0726
authorBram Moolenaar <Bram@vim.org>
Sat, 9 May 2020 21:20:20 +0000 (23:20 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 9 May 2020 21:20:20 +0000 (23:20 +0200)
Problem:    Vim9: leaking memory when calling not compiled :def function.
Solution:   Check if function is compiled earlier.

src/version.c
src/vim9execute.c

index bc93675ab4b4b1971e3a21425de26bf571849af3..ef7dedb98007558a83a84e20f325038f447ce304 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    726,
 /**/
     725,
 /**/
index bfa24928a85214246a5c7897bcaf289f8e03c926..4d4df0ab60d6f28cf02dd75dd79484b90866b58f 100644 (file)
@@ -665,10 +665,6 @@ call_def_function(
 // Like STACK_TV_VAR but use the outer scope
 #define STACK_OUT_TV_VAR(idx) (((typval_T *)ectx.ec_outer_stack->ga_data) + ectx.ec_outer_frame + STACK_FRAME_SIZE + idx)
 
-    CLEAR_FIELD(ectx);
-    ga_init2(&ectx.ec_stack, sizeof(typval_T), 500);
-    if (ga_grow(&ectx.ec_stack, 20) == FAIL)
-       return FAIL;
     {
        // Check the function was compiled, it is postponed in ex_vim9script().
        dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
@@ -676,8 +672,12 @@ call_def_function(
        if (dfunc->df_instr == NULL)
            return FAIL;
     }
-    ectx.ec_dfunc_idx = ufunc->uf_dfunc_idx;
 
+    CLEAR_FIELD(ectx);
+    ectx.ec_dfunc_idx = ufunc->uf_dfunc_idx;
+    ga_init2(&ectx.ec_stack, sizeof(typval_T), 500);
+    if (ga_grow(&ectx.ec_stack, 20) == FAIL)
+       return FAIL;
     ga_init2(&ectx.ec_trystack, sizeof(trycmd_T), 10);
 
     // Put arguments on the stack.