Patch 8.2.0697
Problem:    Vim9: memory leak when using nested function.
Solution:   Unreference function when deleting instructions. Adjust reference
            count for local variables.
Files:      src/vim9compile.c, src/vim9execute.c


*** ../vim-8.2.0696/src/vim9compile.c   2020-05-05 17:53:12.809623291 +0200
--- src/vim9compile.c   2020-05-05 19:10:15.538275847 +0200
***************
*** 6629,6634 ****
--- 6629,6642 ----
            vim_free(isn->isn_arg.ufunc.cuf_name);
            break;
  
+       case ISN_FUNCREF:
+           {
+               dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
+                                              + isn->isn_arg.funcref.fr_func;
+               func_ptr_unref(dfunc->df_ufunc);
+           }
+           break;
+ 
        case ISN_2BOOL:
        case ISN_2STRING:
        case ISN_ADDBLOB:
***************
*** 6657,6663 ****
        case ISN_EXECCONCAT:
        case ISN_EXECUTE:
        case ISN_FOR:
-       case ISN_FUNCREF:
        case ISN_INDEX:
        case ISN_JUMP:
        case ISN_LOAD:
--- 6665,6670 ----
*** ../vim-8.2.0696/src/vim9execute.c   2020-05-05 17:53:12.809623291 +0200
--- src/vim9execute.c   2020-05-05 19:38:20.483009675 +0200
***************
*** 264,273 ****
      {
        tv = STACK_TV(ectx->ec_frame_idx + STACK_FRAME_SIZE
                                                   + dfunc->df_varcount + idx);
!       if (tv->v_type == VAR_PARTIAL && tv->vval.v_partial->pt_refcount > 1)
        {
!           closure_in_use = TRUE;
!           break;
        }
      }
  
--- 264,290 ----
      {
        tv = STACK_TV(ectx->ec_frame_idx + STACK_FRAME_SIZE
                                                   + dfunc->df_varcount + idx);
!       if (tv->v_type == VAR_PARTIAL && tv->vval.v_partial != NULL
!                                       && tv->vval.v_partial->pt_refcount > 1)
        {
!           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)
!           {
!               typval_T *stv = STACK_TV(ectx->ec_frame_idx
!                                                      + STACK_FRAME_SIZE + i);
!               if (stv->v_type == VAR_PARTIAL
!                                 && tv->vval.v_partial == stv->vval.v_partial)
!                   --refcount;
!           }
!           if (refcount > 1)
!           {
!               closure_in_use = TRUE;
!               break;
!           }
        }
      }
  
*** ../vim-8.2.0696/src/version.c       2020-05-05 17:53:12.809623291 +0200
--- src/version.c       2020-05-05 19:40:22.738554013 +0200
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     697,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
48. You get a tatoo that says "This body best viewed with Netscape 3.1 or
    higher."

 /// Bram Moolenaar -- [email protected] -- 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    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202005051747.045HlOMi009519%40masaka.moolenaar.net.

Raspunde prin e-mail lui