guile-devel
[Top][All Lists]
Advanced

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

Re: [PATCH 1/2] Fix memory leak on `realloc' failure


From: Dmitry Bogatov
Subject: Re: [PATCH 1/2] Fix memory leak on `realloc' failure
Date: Thu, 10 Apr 2014 20:52:43 +0400
User-agent: Mutt/1.5.23 (2014-03-12)

* address@hidden <address@hidden> [2014-04-10 12:36:48-0400]
> > +         {
> > +           free (nargv);
> >             return 0L;
> > +         }
> >         else
> >           nargv[nargi++] = narg;
> I don't understand this.  In both cases, free() will be called with an
> argument of 0, which does nothing.

My bad. It does not fix problem, that if realloc fails, it does not free
memory, but we blindly assign, losing pointer to previous memory chunk.

I will make another patch, like this

void* xrealloc(void *old_ptr, size_t new_size)
{
        void *new_ptr = realloc(old_ptr, new_size);
        if (!new_ptr)
                free(old_ptr);
        return new_ptr;
}

Suggestions, maybe more conventional name?

--
Best regards, Dmitry Bogatov <address@hidden>,
Free Software supporter, esperantisto and netiquette guardian.
        git://kaction.name/rc-files.git
        GPG: 54B7F00D



reply via email to

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