Date: Thu, 20 Aug 1998 18:26:03 -0500 (CDT) From: Joel Ray Holveck <joelh@gnu.org> To: dag-erli@ifi.uio.no Cc: imp@village.org, hackers@FreeBSD.ORG Subject: Re: Realloc fix for review Message-ID: <199808202326.SAA07936@detlev.UUCP> In-Reply-To: <xzplnoj8uq9.fsf@skejdbrimir.ifi.uio.no> (dag-erli@ifi.uio.no) References: <199808201619.KAA20970@harmony.village.org> <xzplnoj8uq9.fsf@skejdbrimir.ifi.uio.no>
next in thread | previous in thread | raw e-mail | index | archive | help
>> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199808202326.SAA07936>