Hi,
I found another memory leak in vim-7.1.137
Steps to reproduce:
1/ start vim with a remote file (content of the actual file does not
matter I think)
$ valgrind --leak-check=yes \
--track-fds=yes \
--num-callers=19 \
./vim http://dominique.pelle.free.fr/.vimrc 2> vg.log
2/ source the file and quit
:so %
:q!
3/ observe that valgrind reports the following leak:
==6256== 20 bytes in 1 blocks are definitely lost in loss record 2 of 15
==6256== at 0x4021620: malloc (vg_replace_malloc.c:149)
==6256== by 0x8102F4C: lalloc (misc2.c:857)
==6256== by 0x8102E6E: alloc (misc2.c:756)
==6256== by 0x81032AD: vim_strsave (misc2.c:1144)
==6256== by 0x80FB289: FullName_save (misc1.c:4693)
==6256== by 0x8051AE2: fix_fname (buffer.c:4182)
==6256== by 0x8096D44: do_source (ex_cmds2.c:2815)
==6256== by 0x8096CB1: cmd_source (ex_cmds2.c:2684)
==6256== by 0x8096C0A: ex_source (ex_cmds2.c:2657)
==6256== by 0x809B897: do_one_cmd (ex_docmd.c:2621)
==6256== by 0x80990FC: do_cmdline (ex_docmd.c:1099)
==6256== by 0x8116F33: nv_colon (normal.c:5168)
==6256== by 0x8111067: normal_cmd (normal.c:1141)
==6256== by 0x80D7D52: main_loop (main.c:1181)
==6256== by 0x80D7966: main (main.c:940)
The problem is in do_source() which returns without
freeing fname_exp at lines 2831 and 2833 in ex_cmds2.c:
2815 fname_exp = fix_fname(p); <--- fname_exp (local var)
dynamically allocated
2816 vim_free(p);
2817 if (fname_exp == NULL)
2818 return retval;
2819 if (mch_isdir(fname_exp))
2820 {
2821 smsg((char_u *)_("Cannot source a directory: \"%s\""), fname);
2822 goto theend;
2823 }
2824
2825 #ifdef FEAT_AUTOCMD
2826 /* Apply SourceCmd autocommands, they should get the file and
source it. */
2827 if (has_autocmd(EVENT_SOURCECMD, fname_exp, NULL)
2828 && apply_autocmds(EVENT_SOURCECMD, fname_exp, fname_exp,
2829
FALSE, curbuf))
2830 # ifdef FEAT_EVAL
2831 return aborting() ? FAIL : OK; <--- return without
freeing fname_exp
2832 # else
2833 return OK; <----------------------- return without
freeing fname_exp
2834 # endif
I attach a patch which fixes the leak.
I used vim-7.1.137 built on Linux with:
- configure --with-features=huge
- changed src/Makefile to compile without optimisation (-O0)
- changed src/Makefile to enable PROFILE_CFLAGS = -DEXITFREE
/Dominique
Attached: fix_mem_leak_do_source.patch (1126 bytes)
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---
Index: ex_cmds2.c
===================================================================
RCS file: /cvsroot/vim/vim7/src/ex_cmds2.c,v
retrieving revision 1.57
diff -c -r1.57 ex_cmds2.c
*** ex_cmds2.c 10 May 2007 18:55:46 -0000 1.57
--- ex_cmds2.c 7 Oct 2007 17:02:45 -0000
***************
*** 2827,2837 ****
if (has_autocmd(EVENT_SOURCECMD, fname_exp, NULL)
&& apply_autocmds(EVENT_SOURCECMD, fname_exp, fname_exp,
FALSE, curbuf))
# ifdef FEAT_EVAL
! return aborting() ? FAIL : OK;
# else
! return OK;
# endif
/* Apply SourcePre autocommands, they may get the file. */
apply_autocmds(EVENT_SOURCEPRE, fname_exp, fname_exp, FALSE, curbuf);
--- 2827,2840 ----
if (has_autocmd(EVENT_SOURCECMD, fname_exp, NULL)
&& apply_autocmds(EVENT_SOURCECMD, fname_exp, fname_exp,
FALSE, curbuf))
+ {
# ifdef FEAT_EVAL
! retval = aborting() ? FAIL : OK;
# else
! retval = OK;
# endif
+ goto theend;
+ }
/* Apply SourcePre autocommands, they may get the file. */
apply_autocmds(EVENT_SOURCEPRE, fname_exp, fname_exp, FALSE, curbuf);