[patch] fixed memory leak (unlikely to happen)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[patch] fixed memory leak (unlikely to happen)

Dominique Pellé
Hi

Following code in src/normal.c is wrong, since it calls 'vim_free(buf)'
which does nothing since it's inside 'if (buf == NULL)':

src/normal.c:

!!5565  buf = (char_u *)vim_realloc(buf, STRLEN(buf) + STRLEN(p) + 1);
!!5566  if (buf == NULL)
  5567  {
!!5568      vim_free(buf);
  5569      vim_free(p);
  5570      return;
  5571  }

Although unlikely to happen, it leaks memory since realloc() does
not free 'buf' if it fails.

Attached patch fixes it.

Regards
-- Dominique

--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

fixed-leak-normal.c.patch (972 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [patch] fixed memory leak (unlikely to happen)

Bram Moolenaar

Dominique Pelle wrote:

> Following code in src/normal.c is wrong, since it calls 'vim_free(buf)'
> which does nothing since it's inside 'if (buf == NULL)':
>
> src/normal.c:
>
> !!5565  buf = (char_u *)vim_realloc(buf, STRLEN(buf) + STRLEN(p) + 1);
> !!5566  if (buf == NULL)
>   5567  {
> !!5568      vim_free(buf);
>   5569      vim_free(p);
>   5570      return;
>   5571  }
>
> Although unlikely to happen, it leaks memory since realloc() does
> not free 'buf' if it fails.
>
> Attached patch fixes it.

Thanks, I'll include it.

--
GALAHAD: No look, really, this isn't nescess ...
PIGLET:  We must examine you.
GALAHAD: There's nothing wrong with ... that.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [hidden email] -- 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.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php