Patch 8.1.2107
Problem:    Various memory leaks reported by asan.
Solution:   Free the memory. (Ozaki Kiichi, closes #5003)
Files:      src/buffer.c, src/change.c, src/eval.c, src/evalfunc.c,
            src/option.c, src/popupwin.c, src/proto/change.pro,
            src/scriptfile.c, src/terminal.c, src/testdir/test_method.vim


*** ../vim-8.1.2106/src/buffer.c        2019-09-28 19:04:06.989029610 +0200
--- src/buffer.c        2019-10-01 16:43:06.399984907 +0200
***************
*** 880,885 ****
--- 880,886 ----
      /* b:changedtick uses an item in buf_T, remove it now */
      dictitem_remove(buf->b_vars, (dictitem_T *)&buf->b_ct_di);
      unref_var_dict(buf->b_vars);
+     remove_listeners(buf);
  #endif
  #ifdef FEAT_LUA
      lua_buffer_free(buf);
***************
*** 908,913 ****
--- 909,915 ----
  #ifdef FEAT_JOB_CHANNEL
      vim_free(buf->b_prompt_text);
      free_callback(&buf->b_prompt_callback);
+     free_callback(&buf->b_prompt_interrupt);
  #endif
  
      buf_hashtab_remove(buf);
*** ../vim-8.1.2106/src/change.c        2019-09-28 19:04:06.989029610 +0200
--- src/change.c        2019-10-01 16:43:06.399984907 +0200
***************
*** 300,306 ****
      int               id = tv_get_number(argvars);
      buf_T     *buf;
  
!     for (buf = firstbuf; buf != NULL; buf = buf->b_next)
      {
        prev = NULL;
        for (lnr = buf->b_listener; lnr != NULL; lnr = next)
--- 300,306 ----
      int               id = tv_get_number(argvars);
      buf_T     *buf;
  
!     FOR_ALL_BUFFERS(buf)
      {
        prev = NULL;
        for (lnr = buf->b_listener; lnr != NULL; lnr = next)
***************
*** 402,407 ****
--- 402,425 ----
        after_updating_screen(TRUE);
      recursive = FALSE;
  }
+ 
+ /*
+  * Remove all listeners associated with "buf".
+  */
+     void
+ remove_listeners(buf_T *buf)
+ {
+     listener_T        *lnr;
+     listener_T        *next;
+ 
+     for (lnr = buf->b_listener; lnr != NULL; lnr = next)
+     {
+       next = lnr->lr_next;
+       free_callback(&lnr->lr_callback);
+       vim_free(lnr);
+     }
+     buf->b_listener = NULL;
+ }
  #endif
  
  /*
*** ../vim-8.1.2106/src/eval.c  2019-09-15 14:32:49.556731456 +0200
--- src/eval.c  2019-10-01 16:43:06.399984907 +0200
***************
*** 2914,2922 ****
                semsg(_(e_missingparen), "lambda");
        }
        clear_tv(rettv);
!       return FAIL;
      }
!     return call_func_rettv(arg, rettv, evaluate, NULL, &base);
  }
  
  /*
--- 2914,2930 ----
                semsg(_(e_missingparen), "lambda");
        }
        clear_tv(rettv);
!       ret = FAIL;
      }
!     else
!       ret = call_func_rettv(arg, rettv, evaluate, NULL, &base);
! 
!     // Clear the funcref afterwards, so that deleting it while
!     // evaluating the arguments is possible (see test55).
!     if (evaluate)
!       clear_tv(&base);
! 
!     return ret;
  }
  
  /*
*** ../vim-8.1.2106/src/evalfunc.c      2019-09-28 19:04:06.989029610 +0200
--- src/evalfunc.c      2019-10-01 16:43:06.403984886 +0200
***************
*** 2213,2220 ****
        {
            if (rettv_list_alloc(rettv) != FAIL && result != NULL)
                list_append_string(rettv->vval.v_list, result, -1);
!           else
!               vim_free(result);
        }
        else
            rettv->vval.v_string = result;
--- 2213,2219 ----
        {
            if (rettv_list_alloc(rettv) != FAIL && result != NULL)
                list_append_string(rettv->vval.v_list, result, -1);
!           vim_free(result);
        }
        else
            rettv->vval.v_string = result;
*** ../vim-8.1.2106/src/option.c        2019-09-28 19:04:06.997029566 +0200
--- src/option.c        2019-10-01 16:43:06.403984886 +0200
***************
*** 686,692 ****
                && (do_buffer || (p->indir & PV_BUF) == 0)
                && !(options[i].flags & P_NODEFAULT)
                && !optval_default(p, varp, FALSE))
!           set_option_default(i, OPT_LOCAL, FALSE);
      }
  
      unblock_autocmds();
--- 686,692 ----
                && (do_buffer || (p->indir & PV_BUF) == 0)
                && !(options[i].flags & P_NODEFAULT)
                && !optval_default(p, varp, FALSE))
!           set_option_default(i, OPT_FREE|OPT_LOCAL, FALSE);
      }
  
      unblock_autocmds();
*** ../vim-8.1.2106/src/popupwin.c      2019-09-25 22:45:31.721534846 +0200
--- src/popupwin.c      2019-10-01 16:43:06.403984886 +0200
***************
*** 3365,3370 ****
--- 3365,3371 ----
            trunc_string(wp->w_popup_title, title, total_width - 2, len);
            screen_puts(title, wp->w_winrow, wp->w_wincol + 1,
                    wp->w_popup_border[0] > 0 ? border_attr[0] : popup_attr);
+           vim_free(title);
        }
  
        // Compute scrollbar thumb position and size.
*** ../vim-8.1.2106/src/proto/change.pro        2019-08-20 20:13:40.330821936 
+0200
--- src/proto/change.pro        2019-10-01 16:50:02.409889501 +0200
***************
*** 7,12 ****
--- 7,13 ----
  void f_listener_remove(typval_T *argvars, typval_T *rettv);
  void may_invoke_listeners(buf_T *buf, linenr_T lnum, linenr_T lnume, int 
added);
  void invoke_listeners(buf_T *buf);
+ void remove_listeners(buf_T *buf);
  void changed_bytes(linenr_T lnum, colnr_T col);
  void appended_lines(linenr_T lnum, long count);
  void appended_lines_mark(linenr_T lnum, long count);
*** ../vim-8.1.2106/src/scriptfile.c    2019-09-15 14:32:49.556731456 +0200
--- src/scriptfile.c    2019-10-01 16:43:06.403984886 +0200
***************
*** 1358,1364 ****
--- 1358,1367 ----
      int                       i;
  
      for (i = script_items.ga_len; i > 0; --i)
+     {
        vim_free(SCRIPT_ITEM(i).sn_name);
+       ga_clear(&SCRIPT_ITEM(i).sn_prl_ga);
+     }
      ga_clear(&script_items);
  }
  
*** ../vim-8.1.2106/src/terminal.c      2019-09-26 23:08:10.505926873 +0200
--- src/terminal.c      2019-10-01 16:43:06.403984886 +0200
***************
*** 4602,4607 ****
--- 4602,4608 ----
      }
  
      ga_clear(&ga_text);
+     ga_clear(&ga_cell);
      vim_free(prev_char);
  
      return max_cells;
***************
*** 4733,4739 ****
            buf = curbuf;
            while (!(curbuf->b_ml.ml_flags & ML_EMPTY))
                ml_delete((linenr_T)1, FALSE);
!           ga_clear(&curbuf->b_term->tl_scrollback);
            redraw_later(NOT_VALID);
        }
      }
--- 4734,4740 ----
            buf = curbuf;
            while (!(curbuf->b_ml.ml_flags & ML_EMPTY))
                ml_delete((linenr_T)1, FALSE);
!           free_scrollback(curbuf->b_term);
            redraw_later(NOT_VALID);
        }
      }
*** ../vim-8.1.2106/src/testdir/test_method.vim 2019-08-23 22:31:33.217176868 
+0200
--- src/testdir/test_method.vim 2019-10-01 16:43:06.403984886 +0200
***************
*** 140,145 ****
--- 140,149 ----
  
    " todo: lambda accepts more arguments than it consumes
    " call assert_fails('eval "text"->{x -> x .. " extended"}("more")', 'E99:')
+ 
+   let l = [1, 2, 3]
+   eval l->{x -> x}()
+   call assert_equal(1, test_refcount(l))
  endfunc
  
  func Test_method_not_supported()
*** ../vim-8.1.2106/src/version.c       2019-10-01 14:19:04.105173130 +0200
--- src/version.c       2019-10-01 16:46:38.242905800 +0200
***************
*** 755,756 ****
--- 755,758 ----
  {   /* Add new patch number below this line */
+ /**/
+     2107,
  /**/

-- 
The early bird gets the worm. The second mouse gets the cheese.

 /// 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/201910011503.x91F3RXt012452%40masaka.moolenaar.net.

Raspunde prin e-mail lui