comparison src/eval.c @ 22541:7d6ba4204f66 v8.2.1819

patch 8.2.1819: Vim9: Memory leak when using a closure Commit: https://github.com/vim/vim/commit/85d5e2b723e6fc233e53252dd5c523944146fbc2 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Oct 10 14:13:01 2020 +0200 patch 8.2.1819: Vim9: Memory leak when using a closure Problem: Vim9: Memory leak when using a closure. Solution: Compute the mininal refcount in the funcstack. Reenable disabled tests.
author Bram Moolenaar <Bram@vim.org>
date Sat, 10 Oct 2020 14:15:04 +0200
parents 35ef9b0a81a3
children eb54d34ecd27
comparison
equal deleted inserted replaced
22540:f0fd5cb81663 22541:7d6ba4204f66
3982 vim_free(pt->pt_name); 3982 vim_free(pt->pt_name);
3983 } 3983 }
3984 else 3984 else
3985 func_ptr_unref(pt->pt_func); 3985 func_ptr_unref(pt->pt_func);
3986 3986
3987 // Decrease the reference count for the context of a closure. If down
3988 // to the minimum it may be time to free it.
3987 if (pt->pt_funcstack != NULL) 3989 if (pt->pt_funcstack != NULL)
3988 { 3990 {
3989 // Decrease the reference count for the context of a closure. If down 3991 --pt->pt_funcstack->fs_refcount;
3990 // to zero free it and clear the variables on the stack. 3992 funcstack_check_refcount(pt->pt_funcstack);
3991 if (--pt->pt_funcstack->fs_refcount == 0)
3992 {
3993 garray_T *gap = &pt->pt_funcstack->fs_ga;
3994 typval_T *stack = gap->ga_data;
3995
3996 for (i = 0; i < gap->ga_len; ++i)
3997 clear_tv(stack + i);
3998 ga_clear(gap);
3999 vim_free(pt->pt_funcstack);
4000 }
4001 pt->pt_funcstack = NULL;
4002 } 3993 }
4003 3994
4004 vim_free(pt); 3995 vim_free(pt);
4005 } 3996 }
4006 3997
4009 * becomes zero. 4000 * becomes zero.
4010 */ 4001 */
4011 void 4002 void
4012 partial_unref(partial_T *pt) 4003 partial_unref(partial_T *pt)
4013 { 4004 {
4014 if (pt != NULL && --pt->pt_refcount <= 0) 4005 if (pt != NULL)
4015 partial_free(pt); 4006 {
4007 if (--pt->pt_refcount <= 0)
4008 partial_free(pt);
4009
4010 // If the reference count goes down to one, the funcstack may be the
4011 // only reference and can be freed if no other partials reference it.
4012 else if (pt->pt_refcount == 1 && pt->pt_funcstack != NULL)
4013 funcstack_check_refcount(pt->pt_funcstack);
4014 }
4016 } 4015 }
4017 4016
4018 /* 4017 /*
4019 * Return the next (unique) copy ID. 4018 * Return the next (unique) copy ID.
4020 * Used for serializing nested structures. 4019 * Used for serializing nested structures.