Path: utzoo!attcan!uunet!wuarchive!cs.utexas.edu!sun-barr!lll-winken!unixhub!shelby!neon!Gang-of-Four!dkeisen From: dkeisen@Gang-of-Four.Stanford.EDU (Dave Eisen) Newsgroups: comp.lang.c Subject: Re: why is free() a void? Message-ID: <1990Oct24.211905.225@Neon.Stanford.EDU> Date: 24 Oct 90 21:19:05 GMT References: <1749@meaddata.meaddata.com> Sender: news@Neon.Stanford.EDU (USENET News System) Organization: Sequoia Peripherals Lines: 28 In article <1749@meaddata.meaddata.com> rob@pmserv.meaddata.com writes: > >As the subject says, I'm curious as to why free() does not return a value. > > "void free(void *p) > ... p MUST be a pointer to space previously allocated by calloc, > malloc, or realloc." (Emphasis on MUST by me.) > >What happens if p WASN'T allocated as it should've been?? How do we know >there was a problem?? Is there really a problem?? > There most certainly is a problem, free can do all kinds of damage if it is passed a pointer to (for instance) static memory. Most frees don't check if the address they are passed makes sense for a free call, most frees have no way of doing this even if they wanted to. So it is up to the programmer to be sure that the memory to be freed was obtained from malloc or its cousins. -- Dave Eisen Home: (415) 323-9757 dkeisen@Gang-of-Four.Stanford.EDU Office: (415) 967-5644 1447 N. Shoreline Blvd. Mountain View, CA 94043