Skip to content

Commit

Permalink
patch 8.1.0130: ":profdel func" does not work if func was called already
Browse files Browse the repository at this point in the history
Problem:    ":profdel func" does not work if func was called already.
            (Dominique Pelle)
Solution:   Reset uf_profiling and add a flag to indicate initialization was
            done.
  • Loading branch information
brammool committed Jun 30, 2018
1 parent 668324e commit ad64809
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 22 deletions.
1 change: 1 addition & 0 deletions src/structs.h
Expand Up @@ -1345,6 +1345,7 @@ typedef struct
garray_T uf_lines; /* function lines */
#ifdef FEAT_PROFILE
int uf_profiling; /* TRUE when func is being profiled */
int uf_prof_initialized;
/* profiling the function as a whole */
int uf_tm_count; /* nr of calls */
proftime_T uf_tm_total; /* time spent in function + children */
Expand Down
52 changes: 30 additions & 22 deletions src/userfunc.c
Expand Up @@ -293,10 +293,6 @@ get_lambda_tv(char_u **arg, typval_T *rettv, int evaluate)
fp->uf_scoped = NULL;

#ifdef FEAT_PROFILE
fp->uf_tml_count = NULL;
fp->uf_tml_total = NULL;
fp->uf_tml_self = NULL;
fp->uf_profiling = FALSE;
if (prof_def_func())
func_do_profile(fp);
#endif
Expand Down Expand Up @@ -706,6 +702,7 @@ call_user_func(
#ifdef FEAT_PROFILE
proftime_T wait_start;
proftime_T call_start;
int started_profiling = FALSE;
#endif

/* If depth of calling is getting too high, don't execute the function */
Expand Down Expand Up @@ -921,7 +918,10 @@ call_user_func(
if (do_profiling == PROF_YES)
{
if (!fp->uf_profiling && has_profiling(FALSE, fp->uf_name, NULL))
{
started_profiling = TRUE;
func_do_profile(fp);
}
if (fp->uf_profiling
|| (fc->caller != NULL && fc->caller->func->uf_profiling))
{
Expand Down Expand Up @@ -965,6 +965,9 @@ call_user_func(
profile_add(&fc->caller->func->uf_tm_children, &call_start);
profile_add(&fc->caller->func->uf_tml_children, &call_start);
}
if (started_profiling)
// make a ":profdel func" stop profiling the function
fp->uf_profiling = FALSE;
}
#endif

Expand Down Expand Up @@ -2522,23 +2525,28 @@ func_do_profile(ufunc_T *fp)
{
int len = fp->uf_lines.ga_len;

if (len == 0)
len = 1; /* avoid getting error for allocating zero bytes */
fp->uf_tm_count = 0;
profile_zero(&fp->uf_tm_self);
profile_zero(&fp->uf_tm_total);
if (fp->uf_tml_count == NULL)
fp->uf_tml_count = (int *)alloc_clear((unsigned) (sizeof(int) * len));
if (fp->uf_tml_total == NULL)
fp->uf_tml_total = (proftime_T *)alloc_clear((unsigned)
(sizeof(proftime_T) * len));
if (fp->uf_tml_self == NULL)
fp->uf_tml_self = (proftime_T *)alloc_clear((unsigned)
(sizeof(proftime_T) * len));
fp->uf_tml_idx = -1;
if (fp->uf_tml_count == NULL || fp->uf_tml_total == NULL
|| fp->uf_tml_self == NULL)
return; /* out of memory */
if (!fp->uf_prof_initialized)
{
if (len == 0)
len = 1; /* avoid getting error for allocating zero bytes */
fp->uf_tm_count = 0;
profile_zero(&fp->uf_tm_self);
profile_zero(&fp->uf_tm_total);
if (fp->uf_tml_count == NULL)
fp->uf_tml_count = (int *)alloc_clear(
(unsigned)(sizeof(int) * len));
if (fp->uf_tml_total == NULL)
fp->uf_tml_total = (proftime_T *)alloc_clear(
(unsigned)(sizeof(proftime_T) * len));
if (fp->uf_tml_self == NULL)
fp->uf_tml_self = (proftime_T *)alloc_clear(
(unsigned)(sizeof(proftime_T) * len));
fp->uf_tml_idx = -1;
if (fp->uf_tml_count == NULL || fp->uf_tml_total == NULL
|| fp->uf_tml_self == NULL)
return; /* out of memory */
fp->uf_prof_initialized = TRUE;
}

fp->uf_profiling = TRUE;
}
Expand Down Expand Up @@ -2568,7 +2576,7 @@ func_dump_profile(FILE *fd)
{
--todo;
fp = HI2UF(hi);
if (fp->uf_profiling)
if (fp->uf_prof_initialized)
{
if (sorttab != NULL)
sorttab[st_len++] = fp;
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -789,6 +789,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
130,
/**/
129,
/**/
Expand Down

10 comments on commit ad64809

@blueyed
Copy link

@blueyed blueyed commented on ad64809 Jul 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brammool
This commit causes a segfault with tests where I am using :profile start and :profile! pattern/to/file with an indent plugin.
I am not using :profdel.

#0  0x000055593398f806 in func_dump_profile (fd=0x555935daeac0) at userfunc.c:2601
#1  0x0000555933844c00 in profile_dump () at ex_cmds2.c:1839
#2  0x00005559339cc5c5 in getout (exitval=1) at main.c:1474
#3  <signal handler called>
#4  0x00005559339907f1 in func_line_end (cookie=cookie@entry=0x555935dafb50)
    at userfunc.c:3379
#5  0x0000555933990978 in get_func_line (c=c@entry=58, cookie=cookie@entry=0x555935dafb50, 
    indent=<optimized out>) at userfunc.c:3287
#6  0x00005559338550fd in do_cmdline (cmdline=cmdline@entry=0x0, 
    fgetline=fgetline@entry=0x555933990850 <get_func_line>, 
    cookie=cookie@entry=0x555935dafb50, flags=flags@entry=7) at ex_docmd.c:936
#7  0x000055593398cb0a in call_user_func (selfdict=<optimized out>, lastline=2, 
    firstline=2, rettv=0x7ffee2fc81a0, argvars=<optimized out>, argcount=<optimized out>, 
    fp=0x555935d51f20) at userfunc.c:942
#8  call_func (funcname=funcname@entry=0x555935d97310 "GetPythonPEPIndent(v:lnum)", 
    len=len@entry=18, rettv=rettv@entry=0x7ffee2fc81a0, argcount_in=argcount_in@entry=1, 
    argvars_in=argvars_in@entry=0x7ffee2fc7d50, argv_func=argv_func@entry=0x0, firstline=2, 
    lastline=2, doesrange=0x7ffee2fc7f30, evaluate=<optimized out>, partial=0x0, 
    selfdict_in=0x0) at userfunc.c:1436
#9  0x000055593398d51c in get_func_tv (
    name=name@entry=0x555935d97310 "GetPythonPEPIndent(v:lnum)", len=18, 
    rettv=rettv@entry=0x7ffee2fc81a0, arg=arg@entry=0x7ffee2fc8198, firstline=2, 
    lastline=2, doesrange=0x7ffee2fc7f30, evaluate=1, partial=0x0, selfdict=0x0)
    at userfunc.c:451
#10 0x000055593381ec30 in eval7 (arg=arg@entry=0x7ffee2fc8198, 
    rettv=rettv@entry=0x7ffee2fc81a0, evaluate=evaluate@entry=1, 
    want_string=want_string@entry=0) at eval.c:4158
#11 0x000055593381f404 in eval6 (arg=arg@entry=0x7ffee2fc8198, 
    rettv=rettv@entry=0x7ffee2fc81a0, evaluate=evaluate@entry=1, 
    want_string=want_string@entry=0) at eval.c:3795
#12 0x00005559338199fd in eval5 (evaluate=1, rettv=0x7ffee2fc81a0, arg=0x7ffee2fc8198)
    at eval.c:3611
#13 eval4 (arg=0x7ffee2fc8198, rettv=0x7ffee2fc81a0, evaluate=1) at eval.c:3495
#14 0x0000555933819d34 in eval3 (arg=arg@entry=0x7ffee2fc8198, 
    rettv=rettv@entry=0x7ffee2fc81a0, evaluate=evaluate@entry=1) at eval.c:3415
#15 0x0000555933819ea4 in eval2 (evaluate=1, rettv=0x7ffee2fc81a0, arg=0x7ffee2fc8198)
    at eval.c:3347
#16 eval1 (arg=0x7ffee2fc8198, rettv=0x7ffee2fc81a0, evaluate=1) at eval.c:3275
#17 0x000055593381a46e in eval_to_number (
    expr=expr@entry=0x555935b94ff0 "GetPythonPEPIndent(v:lnum)") at eval.c:890
#18 0x00005559338a6ad0 in get_expr_indent () at misc1.c:9537
#19 0x000055593380bb36 in fixthisline (get_the_indent=<optimized out>) at edit.c:8095
#20 0x00005559338ad46b in open_line (dir=dir@entry=1, flags=0, 
    second_line_indent=second_line_indent@entry=0) at misc1.c:1790
#21 0x0000555933809f3e in ins_eol (c=<optimized out>) at edit.c:10460
#22 0x0000555933810db0 in edit (cmdchar=cmdchar@entry=105, startln=<optimized out>, count=1)
    at edit.c:1442
#23 0x00005559338c55c6 in invoke_edit (repl=<optimized out>, cmd=105, 
    startln=<optimized out>, cap=<optimized out>, cap=<optimized out>) at normal.c:9261
#24 0x00005559338d1d09 in normal_cmd (oap=0x7ffee2fc8560, toplevel=1) at normal.c:1136
#25 0x00005559339cd19a in main_loop (cmdwin=0, noexmode=0) at main.c:1353
#26 0x00005559339ce309 in vim_main2 () at main.c:915
#27 0x00005559337ec2bd in main (argc=<optimized out>, argv=<optimized out>) at main.c:443

The tests are using vimrunner, and therefor interact with a server using --servername etc.
I've noticed that the server vanished inside the Docker container, but could also reproduce it outside now.
The setup is not that easy, so hopefully I can provide enough information here:

#0  0x000055593398f806 in func_dump_profile (fd=0x555935daeac0) at userfunc.c:2601
2601			    prof_func_line(fd, fp->uf_tml_count[i],
(gdb) p fd
$1 = (FILE *) 0x555935daeac0
(gdb) p fp->uf_tml_count
$2 = (int *) 0x0
(gdb) p i
$3 = 0

The whole code is this:

		for (i = 0; i < fp->uf_lines.ga_len; ++i)
		{
		    if (FUNCLINE(fp, i) == NULL)
			continue;
		    prof_func_line(fd, fp->uf_tml_count[i],
			     &fp->uf_tml_total[i], &fp->uf_tml_self[i], TRUE);
		    fprintf(fd, "%s\n", FUNCLINE(fp, i));
		}

Where this gets used to skip it, but it is not true in this case:
#define FUNCLINE(fp, j) ((char_u **)(fp->uf_lines.ga_data))[j]

/cc @dpelle

@brammool
Copy link
Contributor Author

@brammool brammool commented on ad64809 Jul 22, 2018 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@blueyed
Copy link

@blueyed blueyed commented on ad64809 Jul 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brammool
Thanks for looking into this!

Are you saying that before the patch your code worked OK?

Yes, I've git-bisected it to this commit.

Hmm, maybe you are redefining the function after using it?
Maybe this change helps (just guessing!):

Yes, that fixes it.
Two of the 3 profile files say "Sourced 2 times", so the function get redefined - this is due to how the tests are setup, and I am using getpid() in the profile filename already, to handle the multiple processes.

I've tried an ASAN build, and one of the logs (after this one-line-patch) shows:

… (removed, missing symbols)

Without the one-line patch it looked like only the "20000 bytes" leak was there, but hard to say for me.

I've used make SANITIZER_CFLAGS="-g -O1 -DABORT_ON_INTERNAL_ERROR -DEXITFREE -fsanitize=address -fno-omit-frame-pointer" with Vim, and then export ASAN_OPTIONS="print_stacktrace=1 log_path=/tmp/asan" when running it - both based on what I've found in .travis.yml.

@dpelle
Copy link
Member

@dpelle dpelle commented on ad64809 Jul 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your asan log is not usable because symbols were stripped.
Try again after commenting this line and re-building:

diff --git a/src/Makefile b/src/Makefile
index f2fafa4dc..96dd34f98 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -2210,7 +2210,7 @@ installvimbin: $(VIMTARGET) $(DESTDIR)$(exec_prefix) $(DEST_BIN)
          rm -f $(DEST_BIN)/$(VIMNAME).rm; \
        fi
        $(INSTALL_PROG) $(VIMTARGET) $(DEST_BIN)
-       $(STRIP) $(DEST_BIN)/$(VIMTARGET)
+       #$(STRIP) $(DEST_BIN)/$(VIMTARGET)
        chmod $(BINMOD) $(DEST_BIN)/$(VIMTARGET)
 # may create a link to the new executable from /usr/bin/vi
        -$(LINKIT)

@blueyed
Copy link

@blueyed blueyed commented on ad64809 Jul 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, using STRIP=/bin/true shows:

Direct leak of 20000 byte(s) in 1 object(s) allocated from:
    #0 0x7f113a46f219 in __interceptor_realloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:105
    #1 0x56376dcc1950 in ga_grow …/Vcs/vim/src/misc2.c:2099
    #2 0x56376dbbd072 in script_line_start …/Vcs/vim/src/ex_cmds2.c:5051
    #3 0x56376dbbd9e8 in getsourceline …/Vcs/vim/src/ex_cmds2.c:4806
    #4 0x56376decd786 in ex_function …/Vcs/vim/src/userfunc.c:2112
    #5 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #6 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #7 0x56376dbbea2b in do_source …/Vcs/vim/src/ex_cmds2.c:4572
    #8 0x56376dbbf7bd in source_callback …/Vcs/vim/src/ex_cmds2.c:3438
    #9 0x56376dbbb71a in do_in_path …/Vcs/vim/src/ex_cmds2.c:3543
    #10 0x56376dbbbbdf in do_in_path_and_pp …/Vcs/vim/src/ex_cmds2.c:3603
    #11 0x56376dbbbd62 in source_in_path …/Vcs/vim/src/ex_cmds2.c:3662
    #12 0x56376dbbbd90 in source_runtime …/Vcs/vim/src/ex_cmds2.c:3653
    #13 0x56376dbbc0d9 in ex_runtime …/Vcs/vim/src/ex_cmds2.c:3432
    #14 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #15 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #16 0x56376db58366 in ex_execute …/Vcs/vim/src/eval.c:8193
    #17 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #18 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #19 0x56376ded24da in call_user_func …/Vcs/vim/src/userfunc.c:942
    #20 0x56376ded24da in call_func …/Vcs/vim/src/userfunc.c:1436
    #21 0x56376ded3b2e in get_func_tv …/Vcs/vim/src/userfunc.c:451
    #22 0x56376ded48b8 in ex_call …/Vcs/vim/src/userfunc.c:3096
    #23 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #24 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #25 0x56376dc1bbf7 in apply_autocmds_group …/Vcs/vim/src/fileio.c:9690
    #26 0x56376dc1da26 in apply_autocmds …/Vcs/vim/src/fileio.c:9203
    #27 0x56376dd4baee in did_set_string_option …/Vcs/vim/src/option.c:7712
    #28 0x56376dd54270 in do_set …/Vcs/vim/src/option.c:5214
    #29 0x56376dbc630c in ex_set …/Vcs/vim/src/ex_docmd.c:12226
    #30 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #31 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #32 0x56376db58366 in ex_execute …/Vcs/vim/src/eval.c:8193
    #33 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #34 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #35 0x56376ded24da in call_user_func …/Vcs/vim/src/userfunc.c:942
    #36 0x56376ded24da in call_func …/Vcs/vim/src/userfunc.c:1436
    #37 0x56376ded3b2e in get_func_tv …/Vcs/vim/src/userfunc.c:451

Direct leak of 4848 byte(s) in 13 object(s) allocated from:
    #0 0x7f113a46ed99 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:86
    #1 0x56376dcbcabe in lalloc …/Vcs/vim/src/misc2.c:976
    #2 0x56376dcbe46a in alloc_clear …/Vcs/vim/src/misc2.c:898
    #3 0x56376dec7bf9 in func_do_profile …/Vcs/vim/src/userfunc.c:2540
    #4 0x56376decf57f in ex_function …/Vcs/vim/src/userfunc.c:2431
    #5 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #6 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #7 0x56376dbbea2b in do_source …/Vcs/vim/src/ex_cmds2.c:4572
    #8 0x56376dbbf7bd in source_callback …/Vcs/vim/src/ex_cmds2.c:3438
    #9 0x56376dbbb71a in do_in_path …/Vcs/vim/src/ex_cmds2.c:3543
    #10 0x56376dbbbbdf in do_in_path_and_pp …/Vcs/vim/src/ex_cmds2.c:3603
    #11 0x56376dbbbd62 in source_in_path …/Vcs/vim/src/ex_cmds2.c:3662
    #12 0x56376dbbbd90 in source_runtime …/Vcs/vim/src/ex_cmds2.c:3653
    #13 0x56376dbbc0d9 in ex_runtime …/Vcs/vim/src/ex_cmds2.c:3432
    #14 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #15 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #16 0x56376db58366 in ex_execute …/Vcs/vim/src/eval.c:8193
    #17 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #18 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #19 0x56376ded24da in call_user_func …/Vcs/vim/src/userfunc.c:942
    #20 0x56376ded24da in call_func …/Vcs/vim/src/userfunc.c:1436
    #21 0x56376ded3b2e in get_func_tv …/Vcs/vim/src/userfunc.c:451
    #22 0x56376ded48b8 in ex_call …/Vcs/vim/src/userfunc.c:3096
    #23 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #24 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #25 0x56376dc1bbf7 in apply_autocmds_group …/Vcs/vim/src/fileio.c:9690
    #26 0x56376dc1da26 in apply_autocmds …/Vcs/vim/src/fileio.c:9203
    #27 0x56376dd4baee in did_set_string_option …/Vcs/vim/src/option.c:7712
    #28 0x56376dd54270 in do_set …/Vcs/vim/src/option.c:5214
    #29 0x56376dbc630c in ex_set …/Vcs/vim/src/ex_docmd.c:12226
    #30 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #31 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #32 0x56376db58366 in ex_execute …/Vcs/vim/src/eval.c:8193
    #33 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #34 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #35 0x56376ded24da in call_user_func …/Vcs/vim/src/userfunc.c:942
    #36 0x56376ded24da in call_func …/Vcs/vim/src/userfunc.c:1436
    #37 0x56376ded3b2e in get_func_tv …/Vcs/vim/src/userfunc.c:451

Direct leak of 4848 byte(s) in 13 object(s) allocated from:
    #0 0x7f113a46ed99 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:86
    #1 0x56376dcbcabe in lalloc …/Vcs/vim/src/misc2.c:976
    #2 0x56376dcbe46a in alloc_clear …/Vcs/vim/src/misc2.c:898
    #3 0x56376dec7c31 in func_do_profile …/Vcs/vim/src/userfunc.c:2543
    #4 0x56376decf57f in ex_function …/Vcs/vim/src/userfunc.c:2431
    #5 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #6 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #7 0x56376dbbea2b in do_source …/Vcs/vim/src/ex_cmds2.c:4572
    #8 0x56376dbbf7bd in source_callback …/Vcs/vim/src/ex_cmds2.c:3438
    #9 0x56376dbbb71a in do_in_path …/Vcs/vim/src/ex_cmds2.c:3543
    #10 0x56376dbbbbdf in do_in_path_and_pp …/Vcs/vim/src/ex_cmds2.c:3603
    #11 0x56376dbbbd62 in source_in_path …/Vcs/vim/src/ex_cmds2.c:3662
    #12 0x56376dbbbd90 in source_runtime …/Vcs/vim/src/ex_cmds2.c:3653
    #13 0x56376dbbc0d9 in ex_runtime …/Vcs/vim/src/ex_cmds2.c:3432
    #14 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #15 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #16 0x56376db58366 in ex_execute …/Vcs/vim/src/eval.c:8193
    #17 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #18 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #19 0x56376ded24da in call_user_func …/Vcs/vim/src/userfunc.c:942
    #20 0x56376ded24da in call_func …/Vcs/vim/src/userfunc.c:1436
    #21 0x56376ded3b2e in get_func_tv …/Vcs/vim/src/userfunc.c:451
    #22 0x56376ded48b8 in ex_call …/Vcs/vim/src/userfunc.c:3096
    #23 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #24 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #25 0x56376dc1bbf7 in apply_autocmds_group …/Vcs/vim/src/fileio.c:9690
    #26 0x56376dc1da26 in apply_autocmds …/Vcs/vim/src/fileio.c:9203
    #27 0x56376dd4baee in did_set_string_option …/Vcs/vim/src/option.c:7712
    #28 0x56376dd54270 in do_set …/Vcs/vim/src/option.c:5214
    #29 0x56376dbc630c in ex_set …/Vcs/vim/src/ex_docmd.c:12226
    #30 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #31 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #32 0x56376db58366 in ex_execute …/Vcs/vim/src/eval.c:8193
    #33 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #34 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #35 0x56376ded24da in call_user_func …/Vcs/vim/src/userfunc.c:942
    #36 0x56376ded24da in call_func …/Vcs/vim/src/userfunc.c:1436
    #37 0x56376ded3b2e in get_func_tv …/Vcs/vim/src/userfunc.c:451

Direct leak of 1212 byte(s) in 13 object(s) allocated from:
    #0 0x7f113a46ed99 in __interceptor_malloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:86
    #1 0x56376dcbcabe in lalloc …/Vcs/vim/src/misc2.c:976
    #2 0x56376dcbe46a in alloc_clear …/Vcs/vim/src/misc2.c:898
    #3 0x56376dec7bc2 in func_do_profile …/Vcs/vim/src/userfunc.c:2537
    #4 0x56376decf57f in ex_function …/Vcs/vim/src/userfunc.c:2431
    #5 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #6 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #7 0x56376dbbea2b in do_source …/Vcs/vim/src/ex_cmds2.c:4572
    #8 0x56376dbbf7bd in source_callback …/Vcs/vim/src/ex_cmds2.c:3438
    #9 0x56376dbbb71a in do_in_path …/Vcs/vim/src/ex_cmds2.c:3543
    #10 0x56376dbbbbdf in do_in_path_and_pp …/Vcs/vim/src/ex_cmds2.c:3603
    #11 0x56376dbbbd62 in source_in_path …/Vcs/vim/src/ex_cmds2.c:3662
    #12 0x56376dbbbd90 in source_runtime …/Vcs/vim/src/ex_cmds2.c:3653
    #13 0x56376dbbc0d9 in ex_runtime …/Vcs/vim/src/ex_cmds2.c:3432
    #14 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #15 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #16 0x56376db58366 in ex_execute …/Vcs/vim/src/eval.c:8193
    #17 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #18 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #19 0x56376ded24da in call_user_func …/Vcs/vim/src/userfunc.c:942
    #20 0x56376ded24da in call_func …/Vcs/vim/src/userfunc.c:1436
    #21 0x56376ded3b2e in get_func_tv …/Vcs/vim/src/userfunc.c:451
    #22 0x56376ded48b8 in ex_call …/Vcs/vim/src/userfunc.c:3096
    #23 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #24 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #25 0x56376dc1bbf7 in apply_autocmds_group …/Vcs/vim/src/fileio.c:9690
    #26 0x56376dc1da26 in apply_autocmds …/Vcs/vim/src/fileio.c:9203
    #27 0x56376dd4baee in did_set_string_option …/Vcs/vim/src/option.c:7712
    #28 0x56376dd54270 in do_set …/Vcs/vim/src/option.c:5214
    #29 0x56376dbc630c in ex_set …/Vcs/vim/src/ex_docmd.c:12226
    #30 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #31 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #32 0x56376db58366 in ex_execute …/Vcs/vim/src/eval.c:8193
    #33 0x56376dbe3735 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #34 0x56376dbe3735 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #35 0x56376ded24da in call_user_func …/Vcs/vim/src/userfunc.c:942
    #36 0x56376ded24da in call_func …/Vcs/vim/src/userfunc.c:1436
    #37 0x56376ded3b2e in get_func_tv …/Vcs/vim/src/userfunc.c:451

@blueyed
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently on ad64809, with the one-line patch (for the line numbers).

@blueyed
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On master (without the one-line patch) I get this:

Direct leak of 20000 byte(s) in 1 object(s) allocated from:
    #0 0x7f0836d73219 in __interceptor_realloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cc:105
    #1 0x55d33ec46fbb in ga_grow …/Vcs/vim/src/misc2.c:2099
    #2 0x55d33eb425a5 in script_line_start …/Vcs/vim/src/ex_cmds2.c:5050
    #3 0x55d33eb42f1b in getsourceline …/Vcs/vim/src/ex_cmds2.c:4805
    #4 0x55d33ee53c65 in ex_function …/Vcs/vim/src/userfunc.c:2125
    #5 0x55d33eb68ca3 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #6 0x55d33eb68ca3 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #7 0x55d33eb43f5e in do_source …/Vcs/vim/src/ex_cmds2.c:4571
    #8 0x55d33eb44cf0 in source_callback …/Vcs/vim/src/ex_cmds2.c:3437
    #9 0x55d33eb40c4d in do_in_path …/Vcs/vim/src/ex_cmds2.c:3542
    #10 0x55d33eb41112 in do_in_path_and_pp …/Vcs/vim/src/ex_cmds2.c:3602
    #11 0x55d33eb41295 in source_in_path …/Vcs/vim/src/ex_cmds2.c:3661
    #12 0x55d33eb412c3 in source_runtime …/Vcs/vim/src/ex_cmds2.c:3652
    #13 0x55d33eb4160c in ex_runtime …/Vcs/vim/src/ex_cmds2.c:3431
    #14 0x55d33eb68ca3 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #15 0x55d33eb68ca3 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #16 0x55d33eadd964 in ex_execute …/Vcs/vim/src/eval.c:8194
    #17 0x55d33eb68ca3 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #18 0x55d33eb68ca3 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #19 0x55d33ee589ff in call_user_func …/Vcs/vim/src/userfunc.c:953
    #20 0x55d33ee589ff in call_func …/Vcs/vim/src/userfunc.c:1449
    #21 0x55d33ee5a09f in get_func_tv …/Vcs/vim/src/userfunc.c:454
    #22 0x55d33ee5ae29 in ex_call …/Vcs/vim/src/userfunc.c:3109
    #23 0x55d33eb68ca3 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #24 0x55d33eb68ca3 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #25 0x55d33eba1299 in apply_autocmds_group …/Vcs/vim/src/fileio.c:9692
    #26 0x55d33eba30c8 in apply_autocmds …/Vcs/vim/src/fileio.c:9205
    #27 0x55d33ecd11f0 in did_set_string_option …/Vcs/vim/src/option.c:7713
    #28 0x55d33ecd9972 in do_set …/Vcs/vim/src/option.c:5215
    #29 0x55d33eb4b83f in ex_set …/Vcs/vim/src/ex_docmd.c:12261
    #30 0x55d33eb68ca3 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #31 0x55d33eb68ca3 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #32 0x55d33eadd964 in ex_execute …/Vcs/vim/src/eval.c:8194
    #33 0x55d33eb68ca3 in do_one_cmd …/Vcs/vim/src/ex_docmd.c:2886
    #34 0x55d33eb68ca3 in do_cmdline …/Vcs/vim/src/ex_docmd.c:1040
    #35 0x55d33ee589ff in call_user_func …/Vcs/vim/src/userfunc.c:953
    #36 0x55d33ee589ff in call_func …/Vcs/vim/src/userfunc.c:1449
    #37 0x55d33ee5a09f in get_func_tv …/Vcs/vim/src/userfunc.c:454

@dpelle
Copy link
Member

@dpelle dpelle commented on ad64809 Jul 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you also uncomment out this line in src/Makefile, so that vim frees all data structures before exiting? This is only useful to avoid spurious leak reports:

diff --git a/src/Makefile b/src/Makefile
index f2fafa4dc..f09137e73 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -699,12 +699,12 @@ 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

@blueyed
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dpelle
Still getting this leak with the following:

diff --git i/src/Makefile w/src/Makefile
index f2fafa4dc..965583f62 100644
--- i/src/Makefile
+++ w/src/Makefile
@@ -699,7 +699,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
 
 # Uncomment this line to have Vim call abort() when an internal error is
@@ -1156,7 +1156,7 @@ INSTALL_DATA_R    = cp -r
 
 ### Program to run on installed binary.  Use the second one to disable strip.
 #STRIP = strip
-#STRIP = /bin/true
+STRIP = /bin/true
 
 ### Permissions for binaries  {{{1
 BINMOD = 755

@blueyed
Copy link

@blueyed blueyed commented on ad64809 Aug 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference: should be fixed in 79c2ad5.

Please sign in to comment.