Hi

The following script reproduces a memory leak
which happens when encrypting a buffer several
times with different keys:

$ cat leak.vim
for i in range(1, 5)
  call feedkeys(":X\<CR>foo\<CR>foo\<CR>")
  call feedkeys(":X\<CR>bar\<CR>bar\<CR>")
endfor

$ rm /tmp/foo; valgrind --leak-check=yes vim -u NONE /tmo/foo -S leak.vim

==3281== 84 bytes in 1 blocks are definitely lost in loss record 89 of 114
==3281==    at 0x4024F70: malloc (vg_replace_malloc.c:236)
==3281==    by 0x8115FEE: lalloc (misc2.c:920)
==3281==    by 0x8115EDE: alloc (misc2.c:818)
==3281==    by 0x80FB52A: ml_add_stack (memline.c:3800)
==3281==    by 0x80FB289: ml_find_line (memline.c:3704)
==3281==    by 0x80F9329: ml_get_buf (memline.c:2474)
==3281==    by 0x80F91C5: ml_get (memline.c:2390)
==3281==    by 0x805AE20: chk_modeline (buffer.c:4881)
==3281==    by 0x805AD7C: do_modelines (buffer.c:4846)
==3281==    by 0x805369B: open_buffer (buffer.c:263)
==3281==    by 0x80E9B4F: create_windows (main.c:2545)
==3281==    by 0x80E7613: main (main.c:804)

-> this leak happens only once


==3281== 756 bytes in 9 blocks are definitely lost in loss record 101 of 114
==3281==    at 0x4024F70: malloc (vg_replace_malloc.c:236)
==3281==    by 0x8115FEE: lalloc (misc2.c:920)
==3281==    by 0x8115EDE: alloc (misc2.c:818)
==3281==    by 0x80FB52A: ml_add_stack (memline.c:3800)
==3281==    by 0x80F5EA1: ml_set_crypt_key (memline.c:547)
==3281==    by 0x8142452: did_set_string_option (option.c:5983)
==3281==    by 0x81416F0: set_string_option (option.c:5514)
==3281==    by 0x814684B: set_option_value (option.c:8532)
==3281==    by 0x8119429: get_crypt_key (misc2.c:3943)
==3281==    by 0x80B484E: ex_X (ex_docmd.c:11165)
==3281==    by 0x80A797C: do_one_cmd (ex_docmd.c:2640)
==3281==    by 0x80A5255: do_cmdline (ex_docmd.c:1109)

-> This leak happens 2*n - 1 times
   n being the number of iteration of loop in leak.vim
   In this example: 2*5 - 1 -> 9 blocks leaked

Attached patch fixes it.

Regards
-- Dominique

-- 
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
diff -r 2b33a7678e7b src/memline.c
--- a/src/memline.c	Tue Jun 22 06:28:58 2010 +0200
+++ b/src/memline.c	Wed Jun 23 21:43:02 2010 +0200
@@ -508,6 +508,7 @@
 	idx = 0;		/* start with first index in block 1 */
 	error = 0;
 	buf->b_ml.ml_stack_top = 0;
+	vim_free(buf->b_ml.ml_stack);
 	buf->b_ml.ml_stack = NULL;
 	buf->b_ml.ml_stack_size = 0;	/* no stack yet */
 
@@ -744,7 +745,7 @@
     {
 	if (*dirp == NUL)
 	    break;
-	/* There is a small chance that between chosing the swap file name and
+	/* There is a small chance that between choosing the swap file name and
 	 * creating it, another Vim creates the file.  In that case the
 	 * creation will fail and we will use another directory. */
 	fname = findswapname(buf, &dirp, NULL); /* allocates fname */
@@ -1239,7 +1240,7 @@
 	    MSG_PUTS_ATTR(_(" cannot be used on this computer.\n"),
 							     attr | MSG_HIST);
 	MSG_PUTS_ATTR(_("The file was created on "), attr | MSG_HIST);
-	/* avoid going past the end of a currupted hostname */
+	/* avoid going past the end of a corrupted hostname */
 	b0p->b0_fname[0] = NUL;
 	MSG_PUTS_ATTR(b0p->b0_hname, attr | MSG_HIST);
 	MSG_PUTS_ATTR(_(",\nor the file has been damaged."), attr | MSG_HIST);

Raspunde prin e-mail lui