From owner-freebsd-hackers Thu Aug 20 12:36:32 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id MAA07848 for freebsd-hackers-outgoing; Thu, 20 Aug 1998 12:36:32 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from rover.village.org (rover.village.org [204.144.255.49]) by hub.freebsd.org (8.8.8/8.8.8) with SMTP id MAA07829 for ; Thu, 20 Aug 1998 12:36:25 -0700 (PDT) (envelope-from imp@village.org) Received: from harmony [10.0.0.6] by rover.village.org with esmtp (Exim 1.71 #1) id 0z9a51-0002ms-00; Thu, 20 Aug 1998 13:09:03 -0600 Received: from harmony.village.org (localhost [127.0.0.1]) by harmony.village.org (8.8.8/8.8.3) with ESMTP id NAA21884; Thu, 20 Aug 1998 13:09:39 -0600 (MDT) Message-Id: <199808201909.NAA21884@harmony.village.org> To: "Jordan K. Hubbard" Subject: Re: Realloc fix for review Cc: dag-erli@ifi.uio.no (Dag-Erling Coidan =?iso-8859-1?Q?Sm=F8rgrav?= ), hackers@FreeBSD.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> Date: Thu, 20 Aug 1998 13:09:38 -0600 From: Warner Losh Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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