]> granicus.if.org Git - vim/commitdiff
patch 8.2.0504: Vim9: leaking scope memory when compilation fails v8.2.0504
authorBram Moolenaar <Bram@vim.org>
Thu, 2 Apr 2020 20:57:36 +0000 (22:57 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 2 Apr 2020 20:57:36 +0000 (22:57 +0200)
Problem:    Vim9: leaking scope memory when compilation fails.
Solution:   Cleanup the scope list.

src/version.c
src/vim9compile.c

index 528454b232341dee8edeb3476500947f9e3e409a..0e7e8c281eef5bbea187fadba3e1478a7f6903e2 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    504,
 /**/
     503,
 /**/
index 83661720542eac77bbc1b96e69690f5c55c60554..3ce04a14a9154dbad138e93fd22f8633169e5ad6 100644 (file)
@@ -3995,6 +3995,18 @@ compile_fill_jump_to_end(endlabel_T **el, cctx_T *cctx)
     }
 }
 
+    static void
+compile_free_jump_to_end(endlabel_T **el)
+{
+    while (*el != NULL)
+    {
+       endlabel_T  *cur = (*el);
+
+       *el = cur->el_next;
+       vim_free(cur);
+    }
+}
+
 /*
  * Create a new scope and set up the generic items.
  */
@@ -4026,6 +4038,20 @@ drop_scope(cctx_T *cctx)
        return;
     }
     cctx->ctx_scope = scope->se_outer;
+    switch (scope->se_type)
+    {
+       case IF_SCOPE:
+           compile_free_jump_to_end(&scope->se_u.se_if.is_end_label); break;
+       case FOR_SCOPE:
+           compile_free_jump_to_end(&scope->se_u.se_for.fs_end_label); break;
+       case WHILE_SCOPE:
+           compile_free_jump_to_end(&scope->se_u.se_while.ws_end_label); break;
+       case TRY_SCOPE:
+           compile_free_jump_to_end(&scope->se_u.se_try.ts_end_label); break;
+       case NO_SCOPE:
+       case BLOCK_SCOPE:
+           break;
+    }
     vim_free(scope);
 }
 
@@ -5519,6 +5545,9 @@ erret:
        if (!dfunc->df_deleted)
            --def_functions.ga_len;
 
+       while (cctx.ctx_scope != NULL)
+           drop_scope(&cctx);
+
        // Don't execute this function body.
        ga_clear_strings(&ufunc->uf_lines);