Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Aug 1998 18:38:13 -0400 (EDT)
From:      Thomas David Rivers <rivers@dignus.com>
To:        dag-erli@ifi.uio.no, nate@mt.sri.com
Cc:        hackers@FreeBSD.ORG, imp@village.org
Subject:   Re: Realloc fix for review
Message-ID:  <199808202238.SAA00904@lakes.dignus.com>
In-Reply-To: <199808201943.NAA07889@mt.sri.com>

next in thread | previous in thread | raw e-mail | index | archive | help
> 
> > > Recently, OpenBSD went through their source tree and fixed all
> > > instances of
> > > 	a = realloc(a, size);
> > > with
> > > 	na = realloc(a, size);
> > > 	if (!na)
> > > 		free(a);
> > > 	a = na;
> > 
> > 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).
> 
> Umm, reread the code again.  His realloc frees the old block when
> realloc *succeeds*, not fails.

  Is that valid - for example, realloc is free to return the
 same pointer if all it needs to do is 'extend' the memory
 descriptor in some way...  I know of realloc() implementations
 that do that.

	- Dave Rivers -


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?199808202238.SAA00904>