Date: Thu, 20 Aug 1998 15:53:39 -0700 (PDT) From: Archie Cobbs <archie@whistle.com> To: imp@village.org (Warner Losh) Cc: eivind@yes.no, hackers@FreeBSD.ORG Subject: Re: Realloc fix for review Message-ID: <199808202253.PAA10143@bubba.whistle.com> In-Reply-To: <199808202221.QAA25040@harmony.village.org> from Warner Losh at "Aug 20, 98 04:21:51 pm"
next in thread | previous in thread | raw e-mail | index | archive | help
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 <insert bug-free code here>, 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199808202253.PAA10143>