From owner-freebsd-hackers Sun Sep 21 19:37:15 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id TAA03939 for hackers-outgoing; Sun, 21 Sep 1997 19:37:15 -0700 (PDT) Received: from ppp6431.on.sympatico.ca (ppp6431.on.sympatico.ca [206.172.208.23]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id TAA03925 for ; Sun, 21 Sep 1997 19:37:05 -0700 (PDT) Received: from localhost (tim@localhost) by ppp6431.on.sympatico.ca (8.8.7/8.8.7) with SMTP id WAA00222; Sun, 21 Sep 1997 22:35:53 -0400 (EDT) Date: Sun, 21 Sep 1997 22:35:52 -0400 (EDT) From: Tim Vanderhoek Reply-To: ac199@hwcn.org To: Sean Eric Fagan cc: hackers@FreeBSD.ORG Subject: Re: Bug in malloc/free (was: Memory leak in getservbyXXX?) In-Reply-To: <199709220129.SAA24046@kithrup.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk On Sun, 21 Sep 1997, Sean Eric Fagan wrote: > Lastly, the wording for free() is, as I understood it when I last read it, > meant to convey the requirement that: > > char *cp = malloc(100); > if (cp) { > free(cp); > cp = malloc(100); > } > > always result in a non-NULL cp. > > So, in conclusion: yes, the OS is perfectly free to have free() return the > memory back to the OS, even though traditional systems did not do this most No, if you want the above code to always result in a non-NULL cp, free() cannot ever return the memory back to the OS. However, I believe the actual wording is sufficiently ambigous that this debate has been fought long and hard in other forums. Anything which is this controversial can be implemented either way and be right. Besides, there ain't no standard which can tell me that free() can't return memory to the OS. -- tIM...HOEk OPTIMIZATION: the process of using many one-letter variables names hoping that the resultant code will run faster.