From owner-freebsd-hackers Thu Aug 20 16:27:08 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id QAA18139 for freebsd-hackers-outgoing; Thu, 20 Aug 1998 16:27:08 -0700 (PDT) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from mail.camalott.com ([208.203.140.2]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id QAA18129 for ; Thu, 20 Aug 1998 16:27:03 -0700 (PDT) (envelope-from joelh@gnu.org) Received: from detlev.UUCP (tex-121.camalott.com [208.229.74.121]) by mail.camalott.com (8.8.7/8.8.5) with ESMTP id SAA17669; Thu, 20 Aug 1998 18:27:43 -0500 Received: (from joelh@localhost) by detlev.UUCP (8.9.1/8.9.1) id SAA07936; Thu, 20 Aug 1998 18:26:03 -0500 (CDT) (envelope-from joelh) Date: Thu, 20 Aug 1998 18:26:03 -0500 (CDT) Message-Id: <199808202326.SAA07936@detlev.UUCP> To: dag-erli@ifi.uio.no CC: imp@village.org, hackers@FreeBSD.ORG In-reply-to: (dag-erli@ifi.uio.no) Subject: Re: Realloc fix for review From: Joel Ray Holveck Reply-to: joelh@gnu.org References: <199808201619.KAA20970@harmony.village.org> 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). Such a change should be done on a per-case basis, rather > than blindly applied to every snippet that calls realloc(). Not to mention that on a large number of programs, memory shortage is fatal so the block will be free'd soon anyway. Happy hacking, joelh -- Joel Ray Holveck - joelh@gnu.org - http://www.wp.com/piquan Fourth law of programming: Anything that can go wrong wi sendmail: segmentation violation - core dumped To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message