Bram Moolenaar wrote:
>> Besides the test failure, several testdir/valgrind.* files
>> show memory leaks, despite having built Vim with
>> -DEXIT_FREE. For example, in valgrind.test_alot, I see:
>
> test_alot is a collection of tests. Can you run them separately to
> isolate the one(s) that causes the leak?
I have not spent a lot of time on this yet. I'll spend more time later.
But this is enough to reproduce leaks (vim built with -DEXITFREE):
# Build vim with -DEXITFREE...
$ git diff Makefile
diff --git a/src/Makefile b/src/Makefile
index 001f87a..21fef20 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -667,7 +667,7 @@ SANITIZER_LIBS = $(SANITIZER_CFLAGS)
# Configuration is in the .ccmalloc or ~/.ccmalloc file.
# Doesn't work very well, since memory linked to from global variables
# (in libraries) is also marked as leaked memory.
-#LEAK_CFLAGS = -DEXITFREE
+LEAK_CFLAGS = -DEXITFREE
#LEAK_LIBS = -lccmalloc
#####################################################
$ ./configure --with-features=huge --enable-gui=none
$ make
$ cd src/testdir
$ valgrind --leak-check=yes ../vim -u NONE -N \
-S test_partial.vim -c 'call Test_job_start_fails()' -c q 2> log
And log file contains:
==6856== Memcheck, a memory error detector
==6856== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==6856== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==6856== Command: ../vim -u NONE -N -S test_partial.vim -c call\
Test_job_start_fails() -c q
==6856==
==6857==
==6857== HEAP SUMMARY:
==6857== in use at exit: 350,433 bytes in 1,828 blocks
==6857== total heap usage: 7,668 allocs, 5,840 frees, 844,057 bytes allocated
==6857==
==6857== 99 bytes in 19 blocks are possibly lost in loss record 249 of 379
==6857== at 0x4C2AB80: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6857== by 0x4C1E2B: lalloc (misc2.c:920)
==6857== by 0x4C26CD: alloc (misc2.c:818)
==6857== by 0x4C26CD: vim_strsave (misc2.c:1256)
==6857== by 0x57AD1B: get_function_args (userfunc.c:207)
==6857== by 0x57DC42: ex_function (userfunc.c:1865)
==6857== by 0x467D0C: do_one_cmd (ex_docmd.c:2925)
==6857== by 0x467D0C: do_cmdline (ex_docmd.c:1110)
==6857== by 0x45C281: do_source (ex_cmds2.c:3975)
==6857== by 0x45CCEB: cmd_source (ex_cmds2.c:3588)
==6857== by 0x467D0C: do_one_cmd (ex_docmd.c:2925)
==6857== by 0x467D0C: do_cmdline (ex_docmd.c:1110)
==6857== by 0x408571: exe_commands (main.c:2893)
==6857== by 0x408571: main (main.c:778)
==6857==
==6857== 192 bytes in 8 blocks are possibly lost in loss record 281 of 379
==6857== at 0x4C2AB80: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6857== by 0x4C1E2B: lalloc (misc2.c:920)
==6857== by 0x4C2F43: alloc (misc2.c:818)
==6857== by 0x4C2F43: ga_grow (misc2.c:2009)
==6857== by 0x57AD07: get_function_args (userfunc.c:201)
==6857== by 0x57DC42: ex_function (userfunc.c:1865)
==6857== by 0x467D0C: do_one_cmd (ex_docmd.c:2925)
==6857== by 0x467D0C: do_cmdline (ex_docmd.c:1110)
==6857== by 0x45C281: do_source (ex_cmds2.c:3975)
==6857== by 0x45CCEB: cmd_source (ex_cmds2.c:3588)
==6857== by 0x467D0C: do_one_cmd (ex_docmd.c:2925)
==6857== by 0x467D0C: do_cmdline (ex_docmd.c:1110)
==6857== by 0x408571: exe_commands (main.c:2893)
==6857== by 0x408571: main (main.c:778)
==6857==
==6857== 216 bytes in 9 blocks are possibly lost in loss record 287 of 379
==6857== at 0x4C2AB80: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6857== by 0x4C1E2B: lalloc (misc2.c:920)
==6857== by 0x4C2F43: alloc (misc2.c:818)
==6857== by 0x4C2F43: ga_grow (misc2.c:2009)
==6857== by 0x57DF1A: ex_function (userfunc.c:2047)
==6857== by 0x467D0C: do_one_cmd (ex_docmd.c:2925)
==6857== by 0x467D0C: do_cmdline (ex_docmd.c:1110)
==6857== by 0x45C281: do_source (ex_cmds2.c:3975)
==6857== by 0x45CCEB: cmd_source (ex_cmds2.c:3588)
==6857== by 0x467D0C: do_one_cmd (ex_docmd.c:2925)
==6857== by 0x467D0C: do_cmdline (ex_docmd.c:1110)
==6857== by 0x408571: exe_commands (main.c:2893)
==6857== by 0x408571: main (main.c:778)
==6857==
==6857== 2,448 bytes in 19 blocks are possibly lost in loss record 350 of 379
==6857== at 0x4C2CE8E: realloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6857== by 0x4C2EF0: ga_grow (misc2.c:2009)
==6857== by 0x57DF1A: ex_function (userfunc.c:2047)
==6857== by 0x467D0C: do_one_cmd (ex_docmd.c:2925)
==6857== by 0x467D0C: do_cmdline (ex_docmd.c:1110)
==6857== by 0x45C281: do_source (ex_cmds2.c:3975)
==6857== by 0x45CCEB: cmd_source (ex_cmds2.c:3588)
==6857== by 0x467D0C: do_one_cmd (ex_docmd.c:2925)
==6857== by 0x467D0C: do_cmdline (ex_docmd.c:1110)
==6857== by 0x408571: exe_commands (main.c:2893)
==6857== by 0x408571: main (main.c:778)
==6857==
==6857== 6,752 bytes in 29 blocks are possibly lost in loss record 365 of 379
==6857== at 0x4C2AB80: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6857== by 0x4C1E2B: lalloc (misc2.c:920)
==6857== by 0x57E784: ex_function (userfunc.c:2175)
==6857== by 0x467D0C: do_one_cmd (ex_docmd.c:2925)
==6857== by 0x467D0C: do_cmdline (ex_docmd.c:1110)
==6857== by 0x45C281: do_source (ex_cmds2.c:3975)
==6857== by 0x45CCEB: cmd_source (ex_cmds2.c:3588)
==6857== by 0x467D0C: do_one_cmd (ex_docmd.c:2925)
==6857== by 0x467D0C: do_cmdline (ex_docmd.c:1110)
==6857== by 0x408571: exe_commands (main.c:2893)
==6857== by 0x408571: main (main.c:778)
==6857==
==6857== 9,265 bytes in 293 blocks are possibly lost in loss record 372 of 379
==6857== at 0x4C2AB80: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6857== by 0x4C1E2B: lalloc (misc2.c:920)
==6857== by 0x4C26CD: alloc (misc2.c:818)
==6857== by 0x4C26CD: vim_strsave (misc2.c:1256)
==6857== by 0x57DF2A: ex_function (userfunc.c:2057)
==6857== by 0x467D0C: do_one_cmd (ex_docmd.c:2925)
==6857== by 0x467D0C: do_cmdline (ex_docmd.c:1110)
==6857== by 0x45C281: do_source (ex_cmds2.c:3975)
==6857== by 0x45CCEB: cmd_source (ex_cmds2.c:3588)
==6857== by 0x467D0C: do_one_cmd (ex_docmd.c:2925)
==6857== by 0x467D0C: do_cmdline (ex_docmd.c:1110)
==6857== by 0x408571: exe_commands (main.c:2893)
==6857== by 0x408571: main (main.c:778)
==6857==
==6857== LEAK SUMMARY:
==6857== definitely lost: 0 bytes in 0 blocks
==6857== indirectly lost: 0 bytes in 0 blocks
==6857== possibly lost: 18,972 bytes in 377 blocks
==6857== still reachable: 331,461 bytes in 1,451 blocks
==6857== suppressed: 0 bytes in 0 blocks
==6857== Reachable blocks (those to which a pointer was found) are not shown.
==6857== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==6857==
==6857== For counts of detected and suppressed errors, rerun with: -v
==6857== ERROR SUMMARY: 6 errors from 6 contexts (suppressed: 0 from 0)
==6856==
==6856== HEAP SUMMARY:
==6856== in use at exit: 108,951 bytes in 429 blocks
==6856== total heap usage: 7,902 allocs, 7,473 frees, 866,261 bytes allocated
==6856==
==6856== 652 (520 direct, 132 indirect) bytes in 1 blocks are
definitely lost in loss record 110 of 132
==6856== at 0x4C2AB80: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6856== by 0x526E8A8: XtMalloc (in /usr/lib/x86_64-linux-gnu/libXt.so.6.0.0)
==6856== by 0x5277250: ??? (in /usr/lib/x86_64-linux-gnu/libXt.so.6.0.0)
==6856== by 0x5277303: ??? (in /usr/lib/x86_64-linux-gnu/libXt.so.6.0.0)
==6856== by 0x5277E61: _XtAppCreateShell (in
/usr/lib/x86_64-linux-gnu/libXt.so.6.0.0)
==6856== by 0x52A5C73: XtVaAppCreateShell (in
/usr/lib/x86_64-linux-gnu/libXt.so.6.0.0)
==6856== by 0x4F8533: setup_term_clip (os_unix.c:6991)
==6856== by 0x407CDE: main (main.c:611)
==6856==
==6856== 1,688 (136 direct, 1,552 indirect) bytes in 1 blocks are
definitely lost in loss record 120 of 132
==6856== at 0x4C2CE8E: realloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6856== by 0x550F0FD: ??? (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6856== by 0x550F657: ??? (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6856== by 0x5510F04: ??? (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6856== by 0x55116BB: _XlcCreateLC (in
/usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6856== by 0x55319CF: _XlcUtf8Loader (in
/usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6856== by 0x5518C4D: _XOpenLC (in
/usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6856== by 0x5518E7A: _XrmInitParseInfo (in
/usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6856== by 0x550153F: ??? (in /usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6856== by 0x550490D: XrmGetStringDatabase (in
/usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6856== by 0x5281495: ??? (in /usr/lib/x86_64-linux-gnu/libXt.so.6.0.0)
==6856== by 0x5282952: _XtDisplayInitialize (in
/usr/lib/x86_64-linux-gnu/libXt.so.6.0.0)
==6856==
==6856== 46,694 (4,680 direct, 42,014 indirect) bytes in 1 blocks are
definitely lost in loss record 132 of 132
==6856== at 0x4C2CC70: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==6856== by 0x54ED85A: XOpenDisplay (in
/usr/lib/x86_64-linux-gnu/libX11.so.6.3.0)
==6856== by 0x4F541A: get_x11_windis (os_unix.c:1835)
==6856== by 0x4F5516: get_x11_thing (os_unix.c:1914)
==6856== by 0x4E9AC4: set_title_defaults (option.c:4127)
==6856== by 0x407C1A: main (main.c:491)
==6856==
==6856== LEAK SUMMARY:
==6856== definitely lost: 5,336 bytes in 3 blocks
==6856== indirectly lost: 43,698 bytes in 64 blocks
==6856== possibly lost: 0 bytes in 0 blocks
==6856== still reachable: 59,917 bytes in 362 blocks
==6856== suppressed: 0 bytes in 0 blocks
==6856== Reachable blocks (those to which a pointer was found) are not shown.
==6856== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==6856==
==6856== For counts of detected and suppressed errors, rerun with: -v
==6856== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)