To: vim_dev@googlegroups.com Subject: Patch 8.2.0704 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0704 Problem: Vim9: memory leak in disassemble test. Solution: Decrement refcount when creating funccal. Files: src/vim9execute.c *** ../vim-8.2.0703/src/vim9execute.c 2020-05-06 21:06:26.421435642 +0200 --- src/vim9execute.c 2020-05-06 22:17:27.226814534 +0200 *************** *** 270,276 **** int refcount = tv->vval.v_partial->pt_refcount; int i; ! // A Reference in a local variables doesn't count, its get // unreferenced on return. for (i = 0; i < dfunc->df_varcount; ++i) { --- 270,276 ---- int refcount = tv->vval.v_partial->pt_refcount; int i; ! // A Reference in a local variables doesn't count, it gets // unreferenced on return. for (i = 0; i < dfunc->df_varcount; ++i) { *************** *** 323,328 **** --- 323,354 ---- for (idx = 0; idx < dfunc->df_varcount; ++idx) { tv = STACK_TV(ectx->ec_frame_idx + STACK_FRAME_SIZE + idx); + + // Do not copy a partial created for a local function. + // TODO: this won't work if the closure actually uses it. But when + // keeping it it gets complicated: it will create a reference cycle + // inside the partial, thus needs special handling for garbage + // collection. + if (tv->v_type == VAR_PARTIAL && tv->vval.v_partial != NULL) + { + int i; + typval_T *ctv; + + for (i = 0; i < dfunc->df_closure_count; ++i) + { + ctv = STACK_TV(ectx->ec_frame_idx + STACK_FRAME_SIZE + + dfunc->df_varcount + i); + if (tv->vval.v_partial == ctv->vval.v_partial) + break; + } + if (i < dfunc->df_closure_count) + { + (stack + argcount + STACK_FRAME_SIZE + idx)->v_type = + VAR_UNKNOWN; + continue; + } + } + *(stack + argcount + STACK_FRAME_SIZE + idx) = *tv; tv->v_type = VAR_UNKNOWN; } *** ../vim-8.2.0703/src/version.c 2020-05-06 21:06:26.425435628 +0200 --- src/version.c 2020-05-06 22:17:39.034775041 +0200 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 704, /**/ -- hundred-and-one symptoms of being an internet addict: 54. You start tilting your head sideways to smile. :-) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///