Skip to content

Commit 3cca299

Browse files
committed
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Problem: Vim9: leaking scope memory when compilation fails. Solution: Cleanup the scope list.
1 parent 585fea7 commit 3cca299

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ static char *(features[]) =
738738

739739
static int included_patches[] =
740740
{ /* Add new patch number below this line */
741+
/**/
742+
504,
741743
/**/
742744
503,
743745
/**/

src/vim9compile.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3995,6 +3995,18 @@ compile_fill_jump_to_end(endlabel_T **el, cctx_T *cctx)
39953995
}
39963996
}
39973997

3998+
static void
3999+
compile_free_jump_to_end(endlabel_T **el)
4000+
{
4001+
while (*el != NULL)
4002+
{
4003+
endlabel_T *cur = (*el);
4004+
4005+
*el = cur->el_next;
4006+
vim_free(cur);
4007+
}
4008+
}
4009+
39984010
/*
39994011
* Create a new scope and set up the generic items.
40004012
*/
@@ -4026,6 +4038,20 @@ drop_scope(cctx_T *cctx)
40264038
return;
40274039
}
40284040
cctx->ctx_scope = scope->se_outer;
4041+
switch (scope->se_type)
4042+
{
4043+
case IF_SCOPE:
4044+
compile_free_jump_to_end(&scope->se_u.se_if.is_end_label); break;
4045+
case FOR_SCOPE:
4046+
compile_free_jump_to_end(&scope->se_u.se_for.fs_end_label); break;
4047+
case WHILE_SCOPE:
4048+
compile_free_jump_to_end(&scope->se_u.se_while.ws_end_label); break;
4049+
case TRY_SCOPE:
4050+
compile_free_jump_to_end(&scope->se_u.se_try.ts_end_label); break;
4051+
case NO_SCOPE:
4052+
case BLOCK_SCOPE:
4053+
break;
4054+
}
40294055
vim_free(scope);
40304056
}
40314057

@@ -5519,6 +5545,9 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
55195545
if (!dfunc->df_deleted)
55205546
--def_functions.ga_len;
55215547

5548+
while (cctx.ctx_scope != NULL)
5549+
drop_scope(&cctx);
5550+
55225551
// Don't execute this function body.
55235552
ga_clear_strings(&ufunc->uf_lines);
55245553

0 commit comments

Comments
 (0)