From owner-freebsd-hackers Thu Aug 20 12:44:12 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id MAA09523 for freebsd-hackers-outgoing; Thu, 20 Aug 1998 12:44:12 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from ns.mt.sri.com (sri-gw.MT.net [206.127.105.141]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id MAA09455 for ; Thu, 20 Aug 1998 12:44:00 -0700 (PDT) (envelope-from nate@mt.sri.com) Received: from mt.sri.com (rocky.mt.sri.com [206.127.76.100]) by ns.mt.sri.com (8.8.8/8.8.8) with SMTP id NAA08031; Thu, 20 Aug 1998 13:43:14 -0600 (MDT) (envelope-from nate@rocky.mt.sri.com) Received: by mt.sri.com (SMI-8.6/SMI-SVR4) id NAA07889; Thu, 20 Aug 1998 13:43:13 -0600 Date: Thu, 20 Aug 1998 13:43:13 -0600 Message-Id: <199808201943.NAA07889@mt.sri.com> From: Nate Williams MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: dag-erli@ifi.uio.no (Dag-Erling Coidan =?iso-8859-1?Q?Sm=F8rgrav?= ) Cc: Warner Losh , hackers@FreeBSD.ORG Subject: Re: Realloc fix for review In-Reply-To: References: <199808201619.KAA20970@harmony.village.org> X-Mailer: VM 6.34 under 19.16 "Lille" XEmacs Lucid Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > > 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. However, is there any case when you want to copy the data from the old pointer into the new pointer, which would also be a lose with the suggested change. (I don't know if this is legal or not...) Naet To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message