Loading ...
Sorry, an error occurred while loading the content.
 

memory leak in vim-7.1.135 when doing "so %"

Expand Messages
  • Dominique Pelle
    vim seems to be leaking memory when doing :so % with syntax on setting. Steps to reproduce: 1/ create a simple script as follows: $ cat leak.vim leaks
    Message 1 of 4 , Oct 6, 2007
      vim seems to be leaking memory when doing ":so %" with "syntax on" setting.

      Steps to reproduce:

      1/ create a simple script as follows:

      $ cat leak.vim
      " leaks memory when doing ":so %" while this file is loaded in vim
      syntax on

      2/ start vim

      $ valgrind --leak-check=yes vim -u NONE -U NONE leak.vim 2> vg.log

      3/ in vim, source the current buffer (leak.vim), then quit

      :so %
      :q

      4/ observe that valgrind reports a memory leak

      ==18415== 22 bytes in 4 blocks are definitely lost in loss record 2 of 15
      ==18415== at 0x4021620: malloc (vg_replace_malloc.c:149)
      ==18415== by 0x8102F4C: lalloc (misc2.c:857)
      ==18415== by 0x8102E6E: alloc (misc2.c:756)
      ==18415== by 0x818C3B1: get_id_list (syntax.c:5761)
      ==18415== by 0x81898E6: get_syn_options (syntax.c:4338)
      ==18415== by 0x818A5E6: syn_cmd_region (syntax.c:4785)
      ==18415== by 0x818C84A: ex_syntax (syntax.c:5974)
      ==18415== by 0x809B897: do_one_cmd (ex_docmd.c:2621)
      ==18415== by 0x80990FC: do_cmdline (ex_docmd.c:1099)
      ==18415== by 0x80973A1: do_source (ex_cmds2.c:3054)
      ==18415== by 0x8189DBF: syn_cmd_include (syntax.c:4494)
      ==18415== by 0x818C84A: ex_syntax (syntax.c:5974)

      Whenever Ex command ":so %" is run, with "syntax on" in script,
      4 more blocks of memory leak, i.e.:

      - If I do ":so %" once, I see:
      22 bytes in 4 blocks are definitely lost in loss record 2 of 15
      - If I do ":so %" twice, I see:
      44 bytes in 8 blocks are definitely lost in loss record 11 of 15
      - I I do ": so %" three times, I see:
      66 bytes in 12 blocks are definitely lost in loss record 10 of 15
      - etc.

      I built vim-7.1.135 on Linux with:
      - configure --with-features=huge
      - changed src/Makefile to compile without optimisation (-O0)
      - changed src/Makefile to enable PROFILE_CFLAGS = -DEXITFREE

      I don't have a patch as I am unsure where it should be freed.

      -- Dominique

      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_dev" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    • Bram Moolenaar
      ... It s not clear to me what memory is leaked (if any is really leaked, valgrind may give a false warning). When I put this line before syntax on it
      Message 2 of 4 , Oct 6, 2007
        Dominique Pelle wrote:

        > vim seems to be leaking memory when doing ":so %" with "syntax on" setting.
        >
        > Steps to reproduce:
        >
        > 1/ create a simple script as follows:
        >
        > $ cat leak.vim
        > " leaks memory when doing ":so %" while this file is loaded in vim
        > syntax on
        >
        > 2/ start vim
        >
        > $ valgrind --leak-check=yes vim -u NONE -U NONE leak.vim 2> vg.log
        >
        > 3/ in vim, source the current buffer (leak.vim), then quit
        >
        > :so %
        > :q
        >
        > 4/ observe that valgrind reports a memory leak
        >
        > ==18415== 22 bytes in 4 blocks are definitely lost in loss record 2 of 15
        > ==18415== at 0x4021620: malloc (vg_replace_malloc.c:149)
        > ==18415== by 0x8102F4C: lalloc (misc2.c:857)
        > ==18415== by 0x8102E6E: alloc (misc2.c:756)
        > ==18415== by 0x818C3B1: get_id_list (syntax.c:5761)
        > ==18415== by 0x81898E6: get_syn_options (syntax.c:4338)
        > ==18415== by 0x818A5E6: syn_cmd_region (syntax.c:4785)
        > ==18415== by 0x818C84A: ex_syntax (syntax.c:5974)
        > ==18415== by 0x809B897: do_one_cmd (ex_docmd.c:2621)
        > ==18415== by 0x80990FC: do_cmdline (ex_docmd.c:1099)
        > ==18415== by 0x80973A1: do_source (ex_cmds2.c:3054)
        > ==18415== by 0x8189DBF: syn_cmd_include (syntax.c:4494)
        > ==18415== by 0x818C84A: ex_syntax (syntax.c:5974)
        >
        > Whenever Ex command ":so %" is run, with "syntax on" in script,
        > 4 more blocks of memory leak, i.e.:
        >
        > - If I do ":so %" once, I see:
        > 22 bytes in 4 blocks are definitely lost in loss record 2 of 15
        > - If I do ":so %" twice, I see:
        > 44 bytes in 8 blocks are definitely lost in loss record 11 of 15
        > - I I do ": so %" three times, I see:
        > 66 bytes in 12 blocks are definitely lost in loss record 10 of 15
        > - etc.
        >
        > I built vim-7.1.135 on Linux with:
        > - configure --with-features=huge
        > - changed src/Makefile to compile without optimisation (-O0)
        > - changed src/Makefile to enable PROFILE_CFLAGS = -DEXITFREE
        >
        > I don't have a patch as I am unsure where it should be freed.

        It's not clear to me what memory is leaked (if any is really leaked,
        valgrind may give a false warning). When I put this line before "syntax
        on" it appears to disappear:

        let g:vimembedscript= 0

        So it's related to ":syn include".

        --
        Engineers are always delighted to share wisdom, even in areas in which they
        have no experience whatsoever. Their logic provides them with inherent
        insight into any field of expertise. This can be a problem when dealing with
        the illogical people who believe that knowledge can only be derived through
        experience.
        (Scott Adams - The Dilbert principle)

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
        \\\ download, build and distribute -- http://www.A-A-P.org ///
        \\\ help me help AIDS victims -- http://ICCF-Holland.org ///

        --~--~---------~--~----~------------~-------~--~----~
        You received this message from the "vim_dev" maillist.
        For more information, visit http://www.vim.org/maillist.php
        -~----------~----~----~----~------~----~------~--~---
      • Tony Mechelynck
        ... What this setting changes is that it forbids sourcing of syntax/perl.vim, syntax/python.vim, syntax/tcl.vim, syntax/ruby.vim and syntax/scheme.vim from
        Message 3 of 4 , Oct 6, 2007
          Bram Moolenaar wrote:
          >
          > Dominique Pelle wrote:
          >
          >> vim seems to be leaking memory when doing ":so %" with "syntax on" setting.
          >>
          >> Steps to reproduce:
          >>
          >> 1/ create a simple script as follows:
          >>
          >> $ cat leak.vim
          >> " leaks memory when doing ":so %" while this file is loaded in vim
          >> syntax on
          >>
          >> 2/ start vim
          >>
          >> $ valgrind --leak-check=yes vim -u NONE -U NONE leak.vim 2> vg.log
          >>
          >> 3/ in vim, source the current buffer (leak.vim), then quit
          >>
          >> :so %
          >> :q
          >>
          >> 4/ observe that valgrind reports a memory leak
          >>
          >> ==18415== 22 bytes in 4 blocks are definitely lost in loss record 2 of 15
          >> ==18415== at 0x4021620: malloc (vg_replace_malloc.c:149)
          >> ==18415== by 0x8102F4C: lalloc (misc2.c:857)
          >> ==18415== by 0x8102E6E: alloc (misc2.c:756)
          >> ==18415== by 0x818C3B1: get_id_list (syntax.c:5761)
          >> ==18415== by 0x81898E6: get_syn_options (syntax.c:4338)
          >> ==18415== by 0x818A5E6: syn_cmd_region (syntax.c:4785)
          >> ==18415== by 0x818C84A: ex_syntax (syntax.c:5974)
          >> ==18415== by 0x809B897: do_one_cmd (ex_docmd.c:2621)
          >> ==18415== by 0x80990FC: do_cmdline (ex_docmd.c:1099)
          >> ==18415== by 0x80973A1: do_source (ex_cmds2.c:3054)
          >> ==18415== by 0x8189DBF: syn_cmd_include (syntax.c:4494)
          >> ==18415== by 0x818C84A: ex_syntax (syntax.c:5974)
          >>
          >> Whenever Ex command ":so %" is run, with "syntax on" in script,
          >> 4 more blocks of memory leak, i.e.:
          >>
          >> - If I do ":so %" once, I see:
          >> 22 bytes in 4 blocks are definitely lost in loss record 2 of 15
          >> - If I do ":so %" twice, I see:
          >> 44 bytes in 8 blocks are definitely lost in loss record 11 of 15
          >> - I I do ": so %" three times, I see:
          >> 66 bytes in 12 blocks are definitely lost in loss record 10 of 15
          >> - etc.
          >>
          >> I built vim-7.1.135 on Linux with:
          >> - configure --with-features=huge
          >> - changed src/Makefile to compile without optimisation (-O0)
          >> - changed src/Makefile to enable PROFILE_CFLAGS = -DEXITFREE
          >>
          >> I don't have a patch as I am unsure where it should be freed.
          >
          > It's not clear to me what memory is leaked (if any is really leaked,
          > valgrind may give a false warning). When I put this line before "syntax
          > on" it appears to disappear:
          >
          > let g:vimembedscript= 0
          >
          > So it's related to ":syn include".
          >

          What this setting changes is that it forbids sourcing of syntax/perl.vim,
          syntax/python.vim, syntax/tcl.vim, syntax/ruby.vim and syntax/scheme.vim from
          within syntax/vim.vim so maybe you (Dominique) might want to investigate which
          one(s) of them leak(s) memory. (Rename one or more of them to something else,
          or move them elsewhere -- temporarily of course -- and see if the leak persists.)


          Best regards,
          Tony.
          --
          God may be subtle, but He isn't plain mean.
          -- Albert Einstein

          --~--~---------~--~----~------------~-------~--~----~
          You received this message from the "vim_dev" maillist.
          For more information, visit http://www.vim.org/maillist.php
          -~----------~----~----~----~------~----~------~--~---
        • Dominique Pelle
          ... I can confirm that I also don t see the leak anymore when I add let g:vimembedscript= 0 in the leak.vim script. Following the good advice of Tony, by
          Message 4 of 4 , Oct 7, 2007
            On 10/7/07, Tony Mechelynck <antoine.mechelynck@...> wrote:

            > > It's not clear to me what memory is leaked (if any is really leaked,
            > > valgrind may give a false warning). When I put this line before "syntax
            > > on" it appears to disappear:
            > >
            > > let g:vimembedscript= 0
            > >
            > > So it's related to ":syn include".
            > >
            >
            > What this setting changes is that it forbids sourcing of syntax/perl.vim,
            > syntax/python.vim, syntax/tcl.vim, syntax/ruby.vim and syntax/scheme.vim from
            > within syntax/vim.vim so maybe you (Dominique) might want to investigate which
            > one(s) of them leak(s) memory. (Rename one or more of them to something else,
            > or move them elsewhere -- temporarily of course -- and see if the leak persists.)
            >
            > Best regards,
            > Tony.


            I can confirm that I also don't see the leak
            anymore when I add "let g:vimembedscript= 0"
            in the "leak.vim" script.

            Following the good advice of Tony, by trial and
            error, i.e. commenting pieces of
            /usr/local/share/vim/vim71/syntax/vim.vim,
            I found this:

            - comment out all of ruby python tcl mzscheme ---> no leak
            - enable perl syntax only -----------------------> no leak
            - enable ruby syntax only -----------------------> ***LEAK!***
            - enable python syntax only ---------------------> no leak
            - enable tcl syntax only ------------------------> no leak
            - enable mzscheme syntax only -------------------> no leak

            So the leak (assuming it's not spurious) comes somehow
            from ruby.vim only.

            I will try to narrow down further in ruby.vim later when
            I have time.

            -- Dominique

            --~--~---------~--~----~------------~-------~--~----~
            You received this message from the "vim_dev" maillist.
            For more information, visit http://www.vim.org/maillist.php
            -~----------~----~----~----~------~----~------~--~---
          Your message has been successfully submitted and would be delivered to recipients shortly.