zhangyuting / vim

Automatically exported from code.google.com/p/vim
0 stars 0 forks source link

":echo serverlist()" leaks memory every time it is run. #158

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Description: the Ex command ":echo serverlist()" leaks memory every
time it is run.

What steps will reproduce the problem?

1. Run the following command which run ":echo serverlist()" 20 times
for example (it will result in 20 blocks leaked):

$ valgrind --leak-check=yes \
  --log-file=valgrind.log \
  ./vim -c 'for i in range(20)|echo serverlist()|endfor|q'

2. Observe 20 blocks leaked in valgrind.log:

$ cat valgrind.log
...
==4730== 20 bytes in 20 blocks are definitely lost in loss record 11 of 34
==4730==    at 0x4C2B3F8: malloc (in 
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==4730==    by 0x5269888: XtMalloc (in /usr/lib/x86_64-linux-gnu/libXt.so.6.0.0)
==4730==    by 0x5274B20: XtOpenDisplay (in 
/usr/lib/x86_64-linux-gnu/libXt.so.6.0.0)
==4730==    by 0x5423DD: setup_term_clip (os_unix.c:6704)
==4730==    by 0x4360AE: f_serverlist (eval.c:15007)
==4730==    by 0x44A962: call_func (eval.c:8530)
==4730==    by 0x451213: get_func_tv (eval.c:8343)
==4730==    by 0x44E3D3: eval7 (eval.c:5153)
==4730==    by 0x44EF75: eval6.constprop.106 (eval.c:4805)
==4730==    by 0x44FE63: eval3 (eval.c:4621)
==4730==    by 0x4501C2: eval2 (eval.c:4155)
==4730==    by 0x450AF3: ex_echo (eval.c:4080)
==4730==    by 0x479F1A: do_one_cmd (ex_docmd.c:2689)
==4730==    by 0x47D25C: do_cmdline (ex_docmd.c:1127)
==4730==    by 0x40A480: main (main.c:2898)

What version of the product are you using? On what operating system?

7.4a.44 BETA (huge) on Linux x86_64.

Please provide any additional information below.

Vim leaks here in os_unix.c:

6704     xterm_dpy = XtOpenDisplay(app_context, xterm_display,
6705             "vim_xterm", "Vim_xterm", NULL, 0, &z, &strp);

I suppose that we need to call XtCloseDisplay(xterm_dpy) somewhere
but I'm not sure where it's safe to call it.

Original issue reported on code.google.com by dominiqu...@gmail.com on 24 Jul 2013 at 9:56

GoogleCodeExporter commented 9 years ago
XtCloseDisplay() is intentionally skipped.  In os_unix.c:

#  if 0
    /* Lesstif and Solaris crash here, lose some memory */
    XtCloseDisplay(xterm_dpy);
#  endif

The amount of memory lost is negligible.

Original comment by brammool...@gmail.com on 27 Jul 2013 at 5:33