Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Aug 1998 13:09:38 -0600
From:      Warner Losh <imp@village.org>
To:        "Jordan K. Hubbard" <jkh@time.cdrom.com>
Cc:        dag-erli@ifi.uio.no (Dag-Erling Coidan =?iso-8859-1?Q?Sm=F8rgrav?= ), hackers@FreeBSD.ORG
Subject:   Re: Realloc fix for review 
Message-ID:  <199808201909.NAA21884@harmony.village.org>
In-Reply-To: Your message of "Thu, 20 Aug 1998 11:42:02 PDT." <25422.903638522@time.cdrom.com> 
References:  <25422.903638522@time.cdrom.com>  

next in thread | previous in thread | raw e-mail | index | archive | help
In message <25422.903638522@time.cdrom.com> "Jordan K. Hubbard" writes:
: > Is that really a good idea? If you free the old block when realloc()
: > fails, you lose whatever data was in it (and therefore potentially
: > lose the ability to generate a sensible error message or recover
: > gracefully). Such a change should be done on a per-case basis, rather
: > than blindly applied to every snippet that calls realloc().
: 
: Hmmm.  In my previous message, I'd also assumed that Warner was only
: talking about changing instances of realloc() where the application
: very definitely wanted the free-on-failure behavior.  Replacing every
: instance of realloc() with the new call would, indeed, be evil
: incarnate given realloc()'s well-documented "I don't fondle the
: previous value on failure" behavior.  Heck, I thought that was the
: entire reason for a new call in the first place. :-)

No, this only replaces those places where the old pointer was
destroyed rather than a s/realloc/frealloc/g.  I was careful to only
change those places where I knew that matched the pattern
	a = realloc(a,size);
and didn't change those where they had:
	b = realloc(a,size);
Since in the former case you've lost any reference to the old memory,
the right thing to do is to free it up.  Since I couldn't change
realloc to have those semantics, I created frealloc which is easier to
use than realloc() in the cases where you want the old memory freed
when it can't allocate new memory.

Warner

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199808201909.NAA21884>