Path: utzoo!attcan!uunet!samsung!crackers!transfer!lectroid!jjmhome!smds!rh From: rh@smds.UUCP (Richard Harter) Newsgroups: comp.lang.c Subject: Re: why is free() a void? Summary: free is not required to anything intelligent with errors Message-ID: <212@smds.UUCP> Date: 25 Oct 90 03:19:13 GMT References: <1749@meaddata.meaddata.com> Organization: SMDS Inc., Concord, MA Lines: 29 In article <1749@meaddata.meaddata.com>, rob@meaddata.com (Robert E. Lancia) writes: To summarize: Why is free a void function? Why doesn't return something useful if the argument is invalid? The answer is very simple -- the specs for malloc/free were broken in the very beginning (IMHO, of course) and most implementations are broken today. It is easier (and faster) to put the allocation control information in memory adjacent to the allocated block in allocators which use free lists (bit mapped buddy-system allocators are a different matter.) IMNSHO this is not nice. It is a source of mystery bugs. An array overwrite in allocated memory can wipe out control information; the consequence doesn't hit you until much later. A stale or incorrect pointer passed to free is allowed to do its damage without warning. And so on. The specs more or less explicitly provide that the users of malloc/free have all of the responsibility for using them without error. The system is not obliged to do error checking. It is at liberty to do something indeterminately awful if the programmer makes an error. All of this in one of the most primitive and least structured aspects of C. Grumble, grumble, grumble. -- Richard Harter, Software Maintenance and Development Systems, Inc. Net address: jjmhome!smds!rh Phone: 508-369-7398 US Mail: SMDS Inc., PO Box 555, Concord MA 01742 This sentence no verb. This sentence short. This signature done.