Dominique Pellé wrote:

> Dominique Pellé wrote:
>
>> 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)
>
>
> About above leaks: I think that that the following comment in 
> mch_start_job(...)
> at os_unix.c:5215 explains why they happen:
>
> os_unix.c:
>
>   5128     pid = fork();       /* maybe we should use vfork() */
>   5129     if (pid  == -1)
>   5130     {
>   5131         /* failed to fork */
>   5132         goto failed;
>   5133     }
>   5134
>   5135     if (pid == 0)
>   5136     {
>   ....
> !!5214 #ifdef EXITFREE
> !!5215         /* calling free_all_mem() here causes problems. Ignore valgrind
> !!5216          * reporting possibly leaked memory. */
> !!5217 #endif
>   5218         _exit(EXEC_FAILED);         /* exec failed, return
> failure code */
>   5219     }
>
> The child process of fork(...) does not call free_all_mem().
> It's probably not a real leak if it's just about not calling free_all_mem()
> before exiting.
>
> Now about the issue with test_netbeans.vim failing when tests are run
> with valgrind, I still don't know why it happens.
>
> Regards
> Dominique

All test pass after patch 7.4.2108 when using valgrind. Thanks!

I still see leaks in valgrind.test_alot,  Most of them come from
the child process after fork() because we don't call free_all_mem()
in the child process. But 2 leaks (below) come from the parent process.
Perhaps those 2 leaks need to be looked at. I will investigate them
this weekend:

==8980== 15 bytes in 2 blocks are definitely lost in loss record 18 of 138
==8980==    at 0x4C2ABF5: malloc (vg_replace_malloc.c:299)
==8980==    by 0x4E43B1: lalloc (misc2.c:920)
==8980==    by 0x4E427E: alloc (misc2.c:818)
==8980==    by 0x4E481E: vim_strsave (misc2.c:1256)
==8980==    by 0x5F04FB: job_set_options (channel.c:4468)
==8980==    by 0x449141: f_job_setoptions (evalfunc.c:6240)
==8980==    by 0x440F20: call_internal_func (evalfunc.c:982)
==8980==    by 0x5D0F20: call_func (userfunc.c:1314)
==8980==    by 0x5CEF4F: get_func_tv (userfunc.c:483)
==8980==    by 0x5D4863: ex_call (userfunc.c:2849)
==8980==    by 0x46FAB5: do_one_cmd (ex_docmd.c:2925)
==8980==    by 0x46C7A3: do_cmdline (ex_docmd.c:1110)
==8980==    by 0x5D0020: call_user_func (userfunc.c:918)
==8980==    by 0x5D0E42: call_func (userfunc.c:1293)
==8980==    by 0x5CEF4F: get_func_tv (userfunc.c:483)
==8980==    by 0x5D4863: ex_call (userfunc.c:2849)
==8980==    by 0x46FAB5: do_one_cmd (ex_docmd.c:2925)
==8980==    by 0x46C7A3: do_cmdline (ex_docmd.c:1110)
==8980==    by 0x43D375: ex_execute (eval.c:8273)
==8980==    by 0x46FAB5: do_one_cmd (ex_docmd.c:2925)
==8980==    by 0x46C7A3: do_cmdline (ex_docmd.c:1110)
==8980==    by 0x5D0020: call_user_func (userfunc.c:918)
==8980==    by 0x5D0E42: call_func (userfunc.c:1293)
==8980==    by 0x5CEF4F: get_func_tv (userfunc.c:483)
==8980==    by 0x5D4863: ex_call (userfunc.c:2849)
==8980==    by 0x46FAB5: do_one_cmd (ex_docmd.c:2925)
==8980==    by 0x46C7A3: do_cmdline (ex_docmd.c:1110)
==8980==    by 0x46A465: do_source (ex_cmds2.c:3975)
==8980==    by 0x469A77: cmd_source (ex_cmds2.c:3588)
==8980==    by 0x4699C9: ex_source (ex_cmds2.c:3563)
==8980==    by 0x46FAB5: do_one_cmd (ex_docmd.c:2925)
==8980==    by 0x46C7A3: do_cmdline (ex_docmd.c:1110)
==8980==    by 0x46BDDF: do_cmdline_cmd (ex_docmd.c:715)
==8980==    by 0x5F65E0: exe_commands (main.c:2892)
==8980==    by 0x5F39A6: main (main.c:778)
==8980==
==8980== 22 bytes in 2 blocks are definitely lost in loss record 27 of 138
==8980==    at 0x4C2ABF5: malloc (vg_replace_malloc.c:299)
==8980==    by 0x4E43B1: lalloc (misc2.c:920)
==8980==    by 0x4E427E: alloc (misc2.c:818)
==8980==    by 0x4E481E: vim_strsave (misc2.c:1256)
==8980==    by 0x45395F: f_timer_start (evalfunc.c:11933)
==8980==    by 0x440F20: call_internal_func (evalfunc.c:982)
==8980==    by 0x5D0F20: call_func (userfunc.c:1314)
==8980==    by 0x5CEF4F: get_func_tv (userfunc.c:483)
==8980==    by 0x5D4863: ex_call (userfunc.c:2849)
==8980==    by 0x46FAB5: do_one_cmd (ex_docmd.c:2925)
==8980==    by 0x46C7A3: do_cmdline (ex_docmd.c:1110)
==8980==    by 0x5D0020: call_user_func (userfunc.c:918)
==8980==    by 0x5D0E42: call_func (userfunc.c:1293)
==8980==    by 0x5CEF4F: get_func_tv (userfunc.c:483)
==8980==    by 0x5D4863: ex_call (userfunc.c:2849)
==8980==    by 0x46FAB5: do_one_cmd (ex_docmd.c:2925)
==8980==    by 0x46C7A3: do_cmdline (ex_docmd.c:1110)
==8980==    by 0x43D375: ex_execute (eval.c:8273)
==8980==    by 0x46FAB5: do_one_cmd (ex_docmd.c:2925)
==8980==    by 0x46C7A3: do_cmdline (ex_docmd.c:1110)
==8980==    by 0x5D0020: call_user_func (userfunc.c:918)
==8980==    by 0x5D0E42: call_func (userfunc.c:1293)
==8980==    by 0x5CEF4F: get_func_tv (userfunc.c:483)
==8980==    by 0x5D4863: ex_call (userfunc.c:2849)
==8980==    by 0x46FAB5: do_one_cmd (ex_docmd.c:2925)
==8980==    by 0x46C7A3: do_cmdline (ex_docmd.c:1110)
==8980==    by 0x46A465: do_source (ex_cmds2.c:3975)
==8980==    by 0x469A77: cmd_source (ex_cmds2.c:3588)
==8980==    by 0x4699C9: ex_source (ex_cmds2.c:3563)
==8980==    by 0x46FAB5: do_one_cmd (ex_docmd.c:2925)
==8980==    by 0x46C7A3: do_cmdline (ex_docmd.c:1110)
==8980==    by 0x46BDDF: do_cmdline_cmd (ex_docmd.c:715)
==8980==    by 0x5F65E0: exe_commands (main.c:2892)
==8980==    by 0x5F39A6: main (main.c:778)

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

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui