From owner-freebsd-hackers Thu Aug 20 12:36:04 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id MAA07686 for freebsd-hackers-outgoing; Thu, 20 Aug 1998 12:36:04 -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 MAA07542 for ; Thu, 20 Aug 1998 12:35:58 -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 0z9a2U-0002mq-00; Thu, 20 Aug 1998 13:06:26 -0600 Received: from harmony.village.org (localhost [127.0.0.1]) by harmony.village.org (8.8.8/8.8.3) with ESMTP id NAA21873; Thu, 20 Aug 1998 13:07:02 -0600 (MDT) Message-Id: <199808201907.NAA21873@harmony.village.org> To: Eivind Eklund Subject: Re: Realloc fix for review Cc: hackers@FreeBSD.ORG In-reply-to: Your message of "Thu, 20 Aug 1998 20:22:34 +0200." <19980820202234.27107@follo.net> References: <19980820202234.27107@follo.net> <199808201619.KAA20970@harmony.village.org> Date: Thu, 20 Aug 1998 13:07:01 -0600 From: Warner Losh Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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