Patch 9.0.1056
Problem:    Leaking memory when disassembling an object method.
Solution:   Free the typval of the class.
Files:      src/vim9class.c


*** ../vim-9.0.1055/src/vim9class.c     2022-12-13 21:14:19.219930894 +0000
--- src/vim9class.c     2022-12-14 15:01:30.098249682 +0000
***************
*** 168,174 ****
                expr_end = expr_start;
                evalarg_T evalarg;
                fill_evalarg_from_eap(&evalarg, eap, FALSE);
!               skip_expr(&expr_end, &evalarg);
  
                if (type == NULL)
                {
--- 168,174 ----
                expr_end = expr_start;
                evalarg_T evalarg;
                fill_evalarg_from_eap(&evalarg, eap, FALSE);
!               skip_expr(&expr_end, NULL);
  
                if (type == NULL)
                {
***************
*** 255,263 ****
      }
      vim_free(theline);
  
      if (success)
      {
!       class_T *cl = ALLOC_CLEAR_ONE(class_T);
        if (cl == NULL)
            goto cleanup;
        cl->class_refcount = 1;
--- 255,264 ----
      }
      vim_free(theline);
  
+     class_T *cl = NULL;
      if (success)
      {
!       cl = ALLOC_CLEAR_ONE(class_T);
        if (cl == NULL)
            goto cleanup;
        cl->class_refcount = 1;
***************
*** 269,280 ****
                                  : ALLOC_MULT(objmember_T, objmembers.ga_len);
        if (cl->class_name == NULL
                || (objmembers.ga_len > 0 && cl->class_obj_members == NULL))
-       {
-           vim_free(cl->class_name);
-           vim_free(cl->class_obj_members);
-           vim_free(cl);
            goto cleanup;
-       }
        mch_memmove(cl->class_obj_members, objmembers.ga_data,
                                      sizeof(objmember_T) * objmembers.ga_len);
        vim_free(objmembers.ga_data);
--- 270,276 ----
***************
*** 338,350 ****
        cl->class_obj_method_count = objmethods.ga_len;
        cl->class_obj_methods = ALLOC_MULT(ufunc_T *, objmethods.ga_len);
        if (cl->class_obj_methods == NULL)
-       {
-           vim_free(cl->class_name);
-           vim_free(cl->class_obj_members);
-           vim_free(cl->class_obj_methods);
-           vim_free(cl);
            goto cleanup;
-       }
        mch_memmove(cl->class_obj_methods, objmethods.ga_data,
                                        sizeof(ufunc_T *) * objmethods.ga_len);
        vim_free(objmethods.ga_data);
--- 334,340 ----
***************
*** 382,387 ****
--- 372,385 ----
      }
  
  cleanup:
+     if (cl != NULL)
+     {
+       vim_free(cl->class_name);
+       vim_free(cl->class_obj_members);
+       vim_free(cl->class_obj_methods);
+       vim_free(cl);
+     }
+ 
      for (int i = 0; i < objmembers.ga_len; ++i)
      {
        objmember_T *m = ((objmember_T *)objmembers.ga_data) + i;
***************
*** 591,609 ****
      if (eval_variable(name, len, 0, &tv, NULL, EVAL_VAR_NOAUTOLOAD) == FAIL)
        return NULL;
      if (tv.v_type != VAR_CLASS && tv.v_type != VAR_OBJECT)
!     {
!       clear_tv(&tv);
!       return NULL;
!     }
  
      class_T *cl = tv.v_type == VAR_CLASS ? tv.vval.v_class
                                                 : tv.vval.v_object->obj_class;
      if (cl == NULL)
!       return NULL;
      char_u *fname = name_end + 1;
      char_u *fname_end = find_name_end(fname, NULL, NULL, FNE_CHECK_START);
      if (fname_end == fname)
!       return NULL;
      len = fname_end - fname;
  
      for (int i = 0; i < cl->class_obj_method_count; ++i)
--- 589,604 ----
      if (eval_variable(name, len, 0, &tv, NULL, EVAL_VAR_NOAUTOLOAD) == FAIL)
        return NULL;
      if (tv.v_type != VAR_CLASS && tv.v_type != VAR_OBJECT)
!       goto fail_after_eval;
  
      class_T *cl = tv.v_type == VAR_CLASS ? tv.vval.v_class
                                                 : tv.vval.v_object->obj_class;
      if (cl == NULL)
!       goto fail_after_eval;
      char_u *fname = name_end + 1;
      char_u *fname_end = find_name_end(fname, NULL, NULL, FNE_CHECK_START);
      if (fname_end == fname)
!       goto fail_after_eval;
      len = fname_end - fname;
  
      for (int i = 0; i < cl->class_obj_method_count; ++i)
***************
*** 613,621 ****
--- 608,621 ----
        // uf_name[] only being 4 characters.
        char_u *ufname = (char_u *)fp->uf_name;
        if (STRNCMP(fname, ufname, len) == 0 && ufname[len] == NUL)
+       {
+           clear_tv(&tv);
            return fp;
+       }
      }
  
+ fail_after_eval:
+     clear_tv(&tv);
      return NULL;
  }
  
*** ../vim-9.0.1055/src/version.c       2022-12-14 13:49:56.214667568 +0000
--- src/version.c       2022-12-14 15:02:32.462180485 +0000
***************
*** 697,698 ****
--- 697,700 ----
  {   /* Add new patch number below this line */
+ /**/
+     1056,
  /**/

-- 
"Never be afraid to tell the world who you are."
                                        -- Anonymous

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            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/20221214150641.C82C01C0CF1%40moolenaar.net.

Raspunde prin e-mail lui