Mercurial > vim
comparison src/eval.c @ 20257:683c2da4982b v8.2.0684
patch 8.2.0684: Vim9: memory leak when using lambda
Commit: https://github.com/vim/vim/commit/f7779c63d4fe531e2483502d4441f24802342768
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun May 3 15:38:16 2020 +0200
patch 8.2.0684: Vim9: memory leak when using lambda
Problem: Vim9: memory leak when using lambda.
Solution: Move the funccal context to the partial. Free the function when
exiting.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 03 May 2020 15:45:05 +0200 |
parents | 06a1dd50463e |
children | bc2c9ea94ec1 |
comparison
equal
deleted
inserted
replaced
20256:e08857045ec1 | 20257:683c2da4982b |
---|---|
3701 func_unref(pt->pt_name); | 3701 func_unref(pt->pt_name); |
3702 vim_free(pt->pt_name); | 3702 vim_free(pt->pt_name); |
3703 } | 3703 } |
3704 else | 3704 else |
3705 func_ptr_unref(pt->pt_func); | 3705 func_ptr_unref(pt->pt_func); |
3706 | |
3707 if (pt->pt_funcstack != NULL) | |
3708 { | |
3709 // Decrease the reference count for the context of a closure. If down | |
3710 // to zero free it and clear the variables on the stack. | |
3711 if (--pt->pt_funcstack->fs_refcount == 0) | |
3712 { | |
3713 garray_T *gap = &pt->pt_funcstack->fs_ga; | |
3714 typval_T *stack = gap->ga_data; | |
3715 | |
3716 for (i = 0; i < gap->ga_len; ++i) | |
3717 clear_tv(stack + i); | |
3718 ga_clear(gap); | |
3719 vim_free(pt->pt_funcstack); | |
3720 } | |
3721 pt->pt_funcstack = NULL; | |
3722 } | |
3723 | |
3706 vim_free(pt); | 3724 vim_free(pt); |
3707 } | 3725 } |
3708 | 3726 |
3709 /* | 3727 /* |
3710 * Unreference a closure: decrement the reference count and free it when it | 3728 * Unreference a closure: decrement the reference count and free it when it |
4334 } | 4352 } |
4335 | 4353 |
4336 for (i = 0; i < pt->pt_argc; ++i) | 4354 for (i = 0; i < pt->pt_argc; ++i) |
4337 abort = abort || set_ref_in_item(&pt->pt_argv[i], copyID, | 4355 abort = abort || set_ref_in_item(&pt->pt_argv[i], copyID, |
4338 ht_stack, list_stack); | 4356 ht_stack, list_stack); |
4357 if (pt->pt_funcstack != NULL) | |
4358 { | |
4359 typval_T *stack = pt->pt_funcstack->fs_ga.ga_data; | |
4360 | |
4361 for (i = 0; i < pt->pt_funcstack->fs_ga.ga_len; ++i) | |
4362 abort = abort || set_ref_in_item(stack + i, copyID, | |
4363 ht_stack, list_stack); | |
4364 } | |
4365 | |
4339 } | 4366 } |
4340 } | 4367 } |
4341 #ifdef FEAT_JOB_CHANNEL | 4368 #ifdef FEAT_JOB_CHANNEL |
4342 else if (tv->v_type == VAR_JOB) | 4369 else if (tv->v_type == VAR_JOB) |
4343 { | 4370 { |