Mercurial > vim
comparison src/vim9compile.c @ 19896:92177b596695 v8.2.0504
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Commit: https://github.com/vim/vim/commit/3cca299520a4980fd1b124564bd67782ca977c15
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Apr 2 22:57:36 2020 +0200
patch 8.2.0504: Vim9: leaking scope memory when compilation fails
Problem: Vim9: leaking scope memory when compilation fails.
Solution: Cleanup the scope list.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 02 Apr 2020 23:00:03 +0200 |
parents | ea4f8e789627 |
children | bd4f91762d0f |
comparison
equal
deleted
inserted
replaced
19895:301db57c7e83 | 19896:92177b596695 |
---|---|
3993 *el = cur->el_next; | 3993 *el = cur->el_next; |
3994 vim_free(cur); | 3994 vim_free(cur); |
3995 } | 3995 } |
3996 } | 3996 } |
3997 | 3997 |
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 | |
3998 /* | 4010 /* |
3999 * Create a new scope and set up the generic items. | 4011 * Create a new scope and set up the generic items. |
4000 */ | 4012 */ |
4001 static scope_T * | 4013 static scope_T * |
4002 new_scope(cctx_T *cctx, scopetype_T type) | 4014 new_scope(cctx_T *cctx, scopetype_T type) |
4024 { | 4036 { |
4025 iemsg("calling drop_scope() without a scope"); | 4037 iemsg("calling drop_scope() without a scope"); |
4026 return; | 4038 return; |
4027 } | 4039 } |
4028 cctx->ctx_scope = scope->se_outer; | 4040 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 } | |
4029 vim_free(scope); | 4055 vim_free(scope); |
4030 } | 4056 } |
4031 | 4057 |
4032 /* | 4058 /* |
4033 * Evaluate an expression that is a constant: | 4059 * Evaluate an expression that is a constant: |
5516 ga_clear(instr); | 5542 ga_clear(instr); |
5517 | 5543 |
5518 ufunc->uf_dfunc_idx = -1; | 5544 ufunc->uf_dfunc_idx = -1; |
5519 if (!dfunc->df_deleted) | 5545 if (!dfunc->df_deleted) |
5520 --def_functions.ga_len; | 5546 --def_functions.ga_len; |
5547 | |
5548 while (cctx.ctx_scope != NULL) | |
5549 drop_scope(&cctx); | |
5521 | 5550 |
5522 // Don't execute this function body. | 5551 // Don't execute this function body. |
5523 ga_clear_strings(&ufunc->uf_lines); | 5552 ga_clear_strings(&ufunc->uf_lines); |
5524 | 5553 |
5525 if (errormsg != NULL) | 5554 if (errormsg != NULL) |