malloc does not return null when out of memory

Steve O'Hara-Smith steve at sohara.org
Fri Jul 25 11:29:54 PDT 2003


On Fri, 25 Jul 2003 07:37:07 +1000
Peter Jeremy <peter.jeremy at alcatel.com.au> wrote:

PJ> I'd suggest adding code in the "malloc_overcommit" path to touch stack
PJ> that is likely to be used, close to the top of {m,c,re}alloc().

	Sounds like a good move.

PJ> There's a gcc-specific extension "__builtin_frame_address()" that will
PJ> let you do this.  This ensures that the stack pages you need are

	Urk - someone who understands the layout of the stack and can
estimate the probable use had better look at doing that if it's going to
happen.

	As for freeing the already allocated memory - what a good idea :)

PJ> present before you try to sbrk() the data.  There may still be other
PJ> corner cases I've missed.
PJ> 
PJ> Cleanly recovering in all cases when there is no additional memory
PJ> available is a very hard problem.  Most of the suggested fixes

	This is true - OTOH the OP would probably be much happier if
malloc could be made to return NULL nearly always when memory can't be
allocated, with a small probability of crashing. It looks like between us
we might manage to produce a patch that will do that much.

-- 
C:>WIN                                      |     Directable Mirrors
The computer obeys and wins.                |A Better Way To Focus The Sun
You lose and Bill collects.                 |  licenses available - see:
                                            |   http://www.sohara.org/


More information about the freebsd-stable mailing list