Hi

The following vim script leaks memory at each iteration, using
latest Vim-7.2.25:

    :set spell
    :while 1
    :    copen
    :    bd
    :endwhile

Run this script with 'vim -u NONE -S leak.vim' and watch memory
increasing steadily.  Valgrind reports this leak:

$ valgrind --leak-check=yes --num-callers=20  vim -u NONE -S leak.vim
...
==14170== 124,288 bytes in 3,884 blocks are definitely lost in loss
record 65 of 65
==14170==    at 0x4022AE8: malloc (vg_replace_malloc.c:207)
==14170==    by 0x81127C4: lalloc (misc2.c:859)
==14170==    by 0x81126FB: alloc_clear (misc2.c:770)
==14170==    by 0x811370D: ga_grow (misc2.c:1981)
==14170==    by 0x817E875: did_set_spelllang (spell.c:4261)
==14170==    by 0x8097922: do_ecmd (ex_cmds.c:3704)
==14170==    by 0x8152AC1: ex_copen (quickfix.c:2336)
==14170==    by 0x80A61E1: do_one_cmd (ex_docmd.c:2621)
==14170==    by 0x80A3A84: do_cmdline (ex_docmd.c:1095)
==14170==    by 0x80A1D20: do_source (ex_cmds2.c:3114)
==14170==    by 0x80A163B: cmd_source (ex_cmds2.c:2741)
==14170==    by 0x80A158F: ex_source (ex_cmds2.c:2714)
==14170==    by 0x80A61E1: do_one_cmd (ex_docmd.c:2621)
==14170==    by 0x80A3A84: do_cmdline (ex_docmd.c:1095)
==14170==    by 0x80A3124: do_cmdline_cmd (ex_docmd.c:701)
==14170==    by 0x80E7600: exe_commands (main.c:2683)
==14170==    by 0x80E500F: main (main.c:873)

The number of blocks leaked (3,884 here) is the number of
iterations in the loop before I hit Ctrl-C.

I'm using Vim-7.2.25, built with -O0 on Linux x86.

Attached patch fixes it (+ typos in comments).

Regards
-- Dominique

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Index: buffer.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/buffer.c,v
retrieving revision 1.83
diff -c -r1.83 buffer.c
*** buffer.c	1 Sep 2008 15:32:55 -0000	1.83
--- buffer.c	22 Oct 2008 01:55:20 -0000
***************
*** 647,652 ****
--- 647,655 ----
      vim_free(buf->b_start_fenc);
      buf->b_start_fenc = NULL;
  #endif
+ #ifdef FEAT_SPELL
+     ga_clear(&buf->b_langp);
+ #endif
  }
  
  /*
***************
*** 1880,1886 ****
  	 * "buf" if one exists */
  	if (swb_flags & SWB_USEOPEN)
  	    wp = buf_jump_open_win(buf);
! 	/* If 'switchbuf' contians "usetab": jump to first window in any tab
  	 * page containing "buf" if one exists */
  	if (wp == NULL && (swb_flags & SWB_USETAB))
  	    wp = buf_jump_open_tab(buf);
--- 1883,1889 ----
  	 * "buf" if one exists */
  	if (swb_flags & SWB_USEOPEN)
  	    wp = buf_jump_open_win(buf);
! 	/* If 'switchbuf' contains "usetab": jump to first window in any tab
  	 * page containing "buf" if one exists */
  	if (wp == NULL && (swb_flags & SWB_USETAB))
  	    wp = buf_jump_open_tab(buf);
***************
*** 3964,3970 ****
      width = vim_strsize(out);
      if (maxwidth > 0 && width > maxwidth)
      {
! 	/* Result is too long, must trunctate somewhere. */
  	l = 0;
  	if (itemcnt == 0)
  	    s = out;
--- 3967,3973 ----
      width = vim_strsize(out);
      if (maxwidth > 0 && width > maxwidth)
      {
! 	/* Result is too long, must truncate somewhere. */
  	l = 0;
  	if (itemcnt == 0)
  	    s = out;

Raspunde prin e-mail lui