malloc does not return null when out of memory

Jason Andresen jandrese at mitre.org
Thu Jul 24 10:27:50 PDT 2003


Barney Wolff wrote:

> On Thu, Jul 24, 2003 at 11:15:43AM -0400, Chuck Swiger wrote:
> 
>>+/* write a single byte per page to disable overcommit behavior */
>>+static int malloc_overcommit;
> 
> 
> Won't this merely die in malloc, not return 0?
> I don't think that's the behavior the original poster was looking for.
> The wanted behavior would be fairly expensive to achieve, especially
> on an smp machine.

The upshot seem to be that it is impossible to write a program that 
handles out-of-memory errors gracefully with this scheme.  Even if you 
check all of your return values and configure exit paths for failed 
mallocs, your program is still going to crash and die in a random 
location without warning when memory fills up.

-- 
   \  |_ _|__ __|_ \ __| Jason Andresen        jandrese at mitre.org
  |\/ |  |    |    / _|  Network and Distributed Systems Engineer
_|  _|___|  _| _|_\___| Office: 703-883-7755




More information about the freebsd-stable mailing list