On Fri, 4 May 2012 15:04:17 +0200 Joerg Sonnenberger
<jo...@britannica.bec.de> wrote:

> On Fri, May 04, 2012 at 10:17:29AM +0900, Cedric BAIL wrote:
> > On Thu, May 3, 2012 at 8:57 PM, Vincent Torri
> > <vincent.to...@gmail.com> wrote:
> > > is it normal that no check is done when calloc is called ?
> > 
> > It's a good question. In E17, there isn't much handling of this
> > situation. I am wrong in assuming that on all unix supported by E17,
> > when it start returning NULL, it would be way to late ?
> > 
> > Should we handle it ?
> 
> You should check for it and fail deterministically at least. Doing
> something like fprintf(stderr, "oops\n"), exit(1); is perfectly valid.
> When malloc and friends fail depends somewhat on the setup. Memory
> overcommit makes the returned error unreliable in the sense that you
> can later get killed by OOM. Using resource limits (ulimit -d / -v
> etc) can result in malloc errors much earlier, but whether you can do
> something sane from that depends on the circumstances. E.g. if the
> user wants to open an image and you can't allocate a buffer, it makes
> sense to report an error for that as the image and therefore the
> buffer can be huge.

Exactly.  The response to any sort of memory allocating problem should
depend on what you are trying to allocate, and why.

Failing to llocate some huge block of memory for something that's not
important? Probably not the end of the world, just fail gracefully on
the unimportant thing.

Failing to allocate a tiny amount for somethung that is very
important?  The system has probably already spent the last five minutes
being unresponsive and thrashing to swap.  Might be a good idea to just
stop now, coz the OOM might kill us anyway.  OR, might be a good idea
to free up some large unimportant resources to help with available
memory.

Just ignoring the failed allocation and trying to use a NULL pointer
will likely crash you anyway, but that's just being lazy.  Failing
gracefully is generally better than failing disgracefully.

-- 
A big old stinking pile of genius that no one wants
coz there are too many silver coated monkeys in the world.

Attachment: signature.asc
Description: PGP signature

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
enlightenment-devel mailing list
enlightenment-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel

Reply via email to