sbrk(2) broken

Dag-Erling Smørgrav des at
Sat Jan 5 05:50:46 PST 2008

Robert Watson <rwatson at> writes:
> Another aspect of the problem is that applications have come to depend
> in malloc(3) returning NULL when memory is getting tight [...]

I don't do that any more.  Unless the program I'm writing is intended to
run for a long time and can gracefully handle an out-of-memory situation
(such as denying client requests until the situation improves), I write
malloc() wrappers which zero the allocated region before returning to
the caller, to force a SIGSEGV and spare the caller from having to check
the return value.

I sometimes also allocate a little bit extra and stick a magic signature
and an allocation length in there so my free() wrapper can check for
bugs and zero the allocated memory before freeing it.  I wouldn't need
any of this if my code only ran on FreeBSD, but most of my $DAYTIME_JOB
code these days runs on Linux first and FreeBSD second.

Dag-Erling Smørgrav - des at

More information about the freebsd-current mailing list