0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.0504: Vim9: leaking scope memory when compilation fails

Problem:    Vim9: leaking scope memory when compilation fails.
Solution:   Cleanup the scope list.
This commit is contained in:
Bram Moolenaar
2020-04-02 22:57:36 +02:00
parent 585fea7b98
commit 3cca299520
2 changed files with 31 additions and 0 deletions

View 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);