Dominique Pelle wrote:

> Valgrind memory checker detects the following memory leak in Vim-7.2.148:
> 
> ==12545== 264 bytes in 4 blocks are definitely lost in loss record 20 of 41
> ==12545==    at 0x402603E: malloc (vg_replace_malloc.c:207)
> ==12545==    by 0x811440D: lalloc (misc2.c:866)
> ==12545==    by 0x8114318: alloc (misc2.c:765)
> ==12545==    by 0x80F68EF: recover_names (memline.c:1536)
> ==12545==    by 0x80F553E: ml_recover (memline.c:891)
> ==12545==    by 0x80AD962: ex_recover (ex_docmd.c:7074)
> ==12545==    by 0x80A6D4B: do_one_cmd (ex_docmd.c:2622)
> ==12545==    by 0x80A45CB: do_cmdline (ex_docmd.c:1096)
> ==12545==    by 0x812A88A: nv_colon (normal.c:5218)
> ==12545==    by 0x8123EEE: normal_cmd (normal.c:1189)
> ==12545==    by 0x80E6C89: main_loop (main.c:1180)
> ==12545==    by 0x80E67D6: main (main.c:939)
> 
> Bug can easily be reproduced as follows:
> 
> 1/ Create an empty directory
> 
>    $ mkdir /tmp/empty_dir
> 
> 2/ Then whenever the following Ex command is entered in Vim,
>    a memory leak happens:
> 
>     :recover /tmp/empty_dir/
> 
> Memory is allocated in memline.c:1536
> 
> 1532    if (swapname != NULL)
> 1533    {
> 1534        if (mch_stat((char *)swapname, &st) != -1)     /* It exists! */
> 1535        {
> 1536            files = (char_u **)alloc((unsigned)sizeof(char_u *));
> 1537            if (files != NULL)
> 1538            {
> 1539                files[0] = swapname;
> 1540                swapname = NULL;
> 1541                num_files = 1;
> 1542            }
> 
> num_files is set to 1 at line 1541.  Then files[0] is freed at
> line 1557 (but files is not freed) and num_files is decremented
> from 1 to 0:
> 
> 1554             for (i = 0; i < num_files; ++i)
> 1555                 if (fullpathcmp(p, files[i], TRUE) & FPC_SAME)
> 1556                 {
> 1557                     vim_free(files[i]);
> 1558                     --num_files;
> 
> files is then no longer freed (leak) since lines that would free it
> is is inside 'if (num_files > 0)':
> 
> 1609         if (num_files > 0)
> 1610             FreeWild(num_files, files);
> 
> Attached patch fixes it.

Thanks!


-- 
CUSTOMER:     You're not fooling anyone y'know.  Look, isn't there something
              you can do?
DEAD PERSON:  I feel happy... I feel happy.
    [whop]
CUSTOMER:     Ah, thanks very much.
MORTICIAN:    Not at all.  See you on Thursday.
CUSTOMER:     Right.
                                  The Quest for the Holy Grail (Monty Python)

 /// Bram Moolenaar -- [email protected] -- 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
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui