From owner-freebsd-stable@FreeBSD.ORG Thu Jul 24 06:54:47 2003 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 57A0537B401 for ; Thu, 24 Jul 2003 06:54:47 -0700 (PDT) Received: from mailhost.firstcallgroup.co.uk (dilbert.firstcallgroup.co.uk [194.200.93.142]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5CBD643F75 for ; Thu, 24 Jul 2003 06:54:46 -0700 (PDT) (envelope-from pfrench@firstcallgroup.co.uk) Received: from pfrench by mailhost.firstcallgroup.co.uk with local (Exim 4.12) id 19fgYM-0007SV-00 for freebsd-stable@freebsd.org; Thu, 24 Jul 2003 14:54:42 +0100 To: freebsd-stable@freebsd.org In-Reply-To: <20030724134104.GA83799@vmunix.com> Message-Id: From: Pete French Date: Thu, 24 Jul 2003 14:54:42 +0100 Subject: Re: malloc does not return null when out of memory X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 24 Jul 2003 13:54:47 -0000 > It's not normal. If malloc cannot allocate memory it should return a > null pointer. How would my application know there is no more memory? But the point is that is *can* allocate the memory. Allocating it is not the same as being able to use it. The behaviour you want is for the system to not only allocate the memory, but to also ensure that the total amount allocated by the system can never exceed the amount the system has available. > page says that malloc will return null when there is no more memory to > be had by the process. It shouldn't return a bogus pointer so I can Its not bogus - the trouble is that you cant tell at the time malloc returns whether the pointer will be useable or not. You only find that out when you try and use it, and whether theres any space or not depends oon what else may have munched up (or released) memory between you making the call to malloc() and actually writing to the location returned. -pcf.