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

Re: patch to fix memory leak in gp and gP commands

Expand Messages
  • Bram Moolenaar
    ... I think what happened is that originally the structure was static and could only keep one register (the static was still there, we don t actually need it
    Message 1 of 2 , Nov 25, 2007
    • 0 Attachment
      Dominique Pelle wrote:

      > Valgrind memory checker detects the following memory leak in vim:
      >
      > ==17553== 48 bytes in 3 blocks are definitely lost in loss record 21 of 42
      > ==17553== at 0x4022765: malloc (vg_replace_malloc.c:149)
      > ==17553== by 0x8112A04: lalloc (misc2.c:857)
      > ==17553== by 0x8112926: alloc (misc2.c:756)
      > ==17553== by 0x81309B8: get_register (ops.c:945)
      > ==17553== by 0x812F221: nv_put (normal.c:8993)
      > ==17553== by 0x812243A: normal_cmd (normal.c:1148)
      > ==17553== by 0x80E53E9: main_loop (main.c:1181)
      > ==17553== by 0x80E4F39: main (main.c:940)
      >
      > I can easily reproduce the memory leak whenever I:
      > - select a visual block
      > - then type gp or gP (see :help gp).
      >
      > Looking at the code, it's clear that memory allocated by
      > get_register() is never freed.
      >
      > I attach a patch which fixes it. An alternative solution would
      > be to free memory inside function put_register(). I'm not sure
      > whether put_register() was intended to free the memory or
      > whether it's up to the caller.
      >
      > I'm using vim-7.1 (patches 1-162) on Linux built with:
      > - ./configure --with-features=huge
      > - compiled with -DEXITFREE -g -O0

      I think what happened is that originally the structure was static and
      could only keep one register (the "static" was still there, we don't
      actually need it now). Later we needed to keep two registers, and the
      memory was allocated. But the matching free was forgotten. I think
      doing it in put_register() is the rigth solution.

      Thanks for finding this and suggesting a solution!

      --
      hundred-and-one symptoms of being an internet addict:
      146. You experience ACTUAL physical withdrawal symptoms when away
      from your 'puter and the net.

      /// 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
      -~----------~----~----~----~------~----~------~--~---
    Your message has been successfully submitted and would be delivered to recipients shortly.