Re: sbrk(2) broken

From: Dag-Erling Smørgrav <des_at_des.no>
Date: Sat, 05 Jan 2008 14:50:37 +0100
Robert Watson <rwatson_at_FreeBSD.org> 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.

DES
-- 
Dag-Erling Smørgrav - des_at_des.no
Received on Sat Jan 05 2008 - 12:50:46 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:25 UTC