From owner-freebsd-hackers Thu Aug 20 15:35:02 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id PAA10957 for freebsd-hackers-outgoing; Thu, 20 Aug 1998 15:35:02 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from elvis.vnet.net (elvis.vnet.net [166.82.1.5]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id PAA10937 for ; Thu, 20 Aug 1998 15:34:56 -0700 (PDT) (envelope-from rivers@dignus.com) Received: from dignus.com (ponds.vnet.net [166.82.177.48]) by elvis.vnet.net (8.8.8/8.8.4) with ESMTP id SAA21341; Thu, 20 Aug 1998 18:34:02 -0400 (EDT) Received: from lakes.dignus.com (lakes [10.0.0.3]) by dignus.com (8.8.8/8.8.5) with ESMTP id TAA10864; Thu, 20 Aug 1998 19:09:06 -0400 (EDT) Received: (from rivers@localhost) by lakes.dignus.com (8.8.8/8.6.9) id SAA00904; Thu, 20 Aug 1998 18:38:13 -0400 (EDT) Date: Thu, 20 Aug 1998 18:38:13 -0400 (EDT) From: Thomas David Rivers Message-Id: <199808202238.SAA00904@lakes.dignus.com> To: dag-erli@ifi.uio.no, nate@mt.sri.com Subject: Re: Realloc fix for review Cc: hackers@FreeBSD.ORG, imp@village.org In-Reply-To: <199808201943.NAA07889@mt.sri.com> 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. 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