bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 2/4] fix a realloc-related memory leak in localhost()


From: Jonathan Neuschäfer
Subject: Re: [PATCH v2 2/4] fix a realloc-related memory leak in localhost()
Date: Sun, 11 Sep 2011 12:00:40 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Wed, Sep 07, 2011 at 05:19:12PM +0200, Thomas Schwinge wrote:
> Hi!
> 
> On Mon, 15 Aug 2011 22:10:07 +0200, Jonathan Neuschäfer 
> <j.neuschaefer@gmx.net> wrote:
> >  * libshouldbeinlibc/localhost.c (localhost): assign the return value
> >    of realloc to a temporary variable to avoid losing the old value of
> >    buf in the case of realloc failing.
> > ---
> >  libshouldbeinlibc/localhost.c |   21 ++++++++++++++-------
> >  1 files changed, 14 insertions(+), 7 deletions(-)
> > 
> > diff --git a/libshouldbeinlibc/localhost.c b/libshouldbeinlibc/localhost.c
> > index f0c6754..f21f970 100644
> > --- a/libshouldbeinlibc/localhost.c
> > +++ b/libshouldbeinlibc/localhost.c
> > @@ -39,18 +39,25 @@ localhost ()
> >     errno = 0;
> >  
> >     if (buf) {
> > +     char *new;
> >       buf_len += buf_len;
> > -     buf = realloc (buf, buf_len);
> > +     new = realloc (buf, buf_len);
> > +     if (! new)
> > +       {
> 
> Am I being dense (which is entirely possible), or did you mean to ``free
> (buf)'' here, or what is the intent here?

I think the intent was to keep the old buffer around, even when realloc
fails, but freeing the buffer is probably a good thing, as the system/
program is under memory pressure at that point.

Greetings,
        Jonathan Neuschäfer



reply via email to

[Prev in Thread] Current Thread [Next in Thread]