Valgrind memory checker detects the following memory leak in vim:
==17553== 48 bytes in 3 blocks are definitely lost in loss record 21 of 42
==17553== at 0x4022765: malloc (vg_replace_malloc.c:149)
==17553== by 0x8112A04: lalloc (misc2.c:857)
==17553== by 0x8112926: alloc (misc2.c:756)
==17553== by 0x81309B8: get_register (ops.c:945)
==17553== by 0x812F221: nv_put (normal.c:8993)
==17553== by 0x812243A: normal_cmd (normal.c:1148)
==17553== by 0x80E53E9: main_loop (main.c:1181)
==17553== by 0x80E4F39: main (main.c:940)
I can easily reproduce the memory leak whenever I:
- select a visual block
- then type gp or gP (see :help gp).
Looking at the code, it's clear that memory allocated by
get_register() is never freed.
I attach a patch which fixes it. An alternative solution would
be to free memory inside function put_register(). I'm not sure
whether put_register() was intended to free the memory or
whether it's up to the caller.
I'm using vim-7.1 (patches 1-162) on Linux built with:
- ./configure --with-features=huge
- compiled with -DEXITFREE -g -O0
Cheers
-- Dominique
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---
Index: normal.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/normal.c,v
retrieving revision 1.100
diff -c -r1.100 normal.c
*** normal.c 14 Oct 2007 15:16:01 -0000 1.100
--- normal.c 24 Nov 2007 23:43:24 -0000
***************
*** 9010,9015 ****
--- 9010,9016 ----
* it first. Then put back what was there before the delete. */
reg2 = get_register(regname, FALSE);
put_register(regname, reg1);
+ vim_free(reg1);
}
/* When deleted a linewise Visual area, put the register as
***************
*** 9036,9042 ****
--- 9037,9046 ----
#ifdef FEAT_VISUAL
/* If a register was saved, put it back now. */
if (reg2 != NULL)
+ {
put_register(regname, reg2);
+ vim_free(reg2);
+ }
/* What to reselect with "gv"? Selecting the just put text seems to
* be the most useful, since the original text was removed. */