Date: Thu, 20 Aug 1998 13:07:01 -0600 From: Warner Losh <imp@village.org> To: Eivind Eklund <eivind@yes.no> Cc: hackers@FreeBSD.ORG Subject: Re: Realloc fix for review Message-ID: <199808201907.NAA21873@harmony.village.org> In-Reply-To: Your message of "Thu, 20 Aug 1998 20:22:34 %2B0200." <19980820202234.27107@follo.net> References: <19980820202234.27107@follo.net> <199808201619.KAA20970@harmony.village.org>
next in thread | previous in thread | raw e-mail | index | archive | help
In message <19980820202234.27107@follo.net> Eivind Eklund writes: : On Thu, Aug 20, 1998 at 10:19:42AM -0600, Warner Losh wrote: : > : > 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; : : This change seems pointless. If the programmer is that thoughtless, : I'd believe he assume a to be valid later, too, and thus will : core-dump pretty soon. If other changes are done in the vicinity, : fine, but replacing the bogus code with a more well-thought-out : function means that we loose the indicator that the area is bogus. : IMO, bad to do without also loosing the bogosity. : : Apart from that, your solution was a nice solution to what I believe : to be the wrong problem :-) No. If you actually go look at most of the code, they aren't so thoughtless as to think that a is valid later. They just destroy the pointer and leak the memory. At least in for the instances in libc that I've fixed. It is surprising how consistant people can be about calling realloc and checking the return vlaue without a thought for leaking memory when they can't realloc for some reason. There are also places where na = realloc(a, newsize); that I left alone. They seemed to already deal with na == NULL and doing the right thing with a. 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?199808201907.NAA21873>
