From owner-freebsd-hackers Thu Aug 20 15:54:29 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id PAA13387 for freebsd-hackers-outgoing; Thu, 20 Aug 1998 15:54:29 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from whistle.com (s205m131.whistle.com [207.76.205.131]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id PAA13378 for ; Thu, 20 Aug 1998 15:54:26 -0700 (PDT) (envelope-from archie@whistle.com) Received: (from smap@localhost) by whistle.com (8.7.5/8.6.12) id PAA00892; Thu, 20 Aug 1998 15:53:46 -0700 (PDT) Received: from bubba.whistle.com(207.76.205.7) by whistle.com via smap (V1.3) id sma000890; Thu Aug 20 15:53:39 1998 Received: (from archie@localhost) by bubba.whistle.com (8.8.7/8.6.12) id PAA10143; Thu, 20 Aug 1998 15:53:39 -0700 (PDT) From: Archie Cobbs Message-Id: <199808202253.PAA10143@bubba.whistle.com> Subject: Re: Realloc fix for review In-Reply-To: <199808202221.QAA25040@harmony.village.org> from Warner Losh at "Aug 20, 98 04:21:51 pm" To: imp@village.org (Warner Losh) Date: Thu, 20 Aug 1998 15:53:39 -0700 (PDT) Cc: eivind@yes.no, hackers@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL38 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Warner Losh writes: > In message <199808202155.OAA09132@bubba.whistle.com> Archie Cobbs writes: > : A better thing would be to replace all instances of "a = realloc(a, size)" > : with , depending on what the program is trying > : to do in that particular instance. > > If you actually look at the code, you'll find that most of the code > that does this realloc, does check to see if a is NULL. The only bug > in most of the code that I've seen is that it doesn't free a in the > failure case. That's why I invented frealloc. > > That is, the code generally deals with failre nearly correctly. for > example, in getcap we have: > record = realloc(record, newsize); > if (record == NULL) { > errno = ENOMEM; > if (myfd) > (void)close(fd); > return (-2); > } > > which clearly does the right thing, except for freeing the old > record.... There are other cases where this is the case. Well, the proof is in the pudding, er source code. In any case, a system-wide scan of this sort of bug would be a good thing IMHO. -Archie ___________________________________________________________________________ Archie Cobbs * Whistle Communications, Inc. * http://www.whistle.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message