Re: Out Of Memory in v. 2.1

Helge Hafting (helge.hafting@daldata.no)
Thu, 08 Oct 1998 08:46:04 +0100


In <5lbtnoe9cd.fsf@tequila.systemsz.cs.yale.edu>, on 10/07/98
at 10:26 AM, Stefan Monnier
<monnier+lists/linux/kernel/news/@TEQUILA.SYSTEMSZ.CS.YALE.EDU> said:

>I actually disagree; malloc should *never* return NULL:
>- as you mentionned, even if it returns non-NULL, the process might end
>up
> killed later because of over-commitment, so returning NULL is only
>sometimes
> useful.
>- most programs don't know what to do when malloc return NULL, so they
>end up
> killing themselves: why bother ask the process to kill itself ?

Many programs doesn't test malloc() for NULL or do a simple exit() if it
happens. But not _all_ programs are written this way!

Some programs clean up files/databases when exiting, letting such programs
quit their own way is a good idea. Some programs can continue just fine
when a NULL is returned from malloc. Some subtask fail of course, but
this may very well be a non-essential subtask.

>i.e. it's a waste of the programmer's time.
Those that don't need to handle OOM can simply use the NULL pointer and
have the program crash with a segmentation fault.
No wasted programmer's time. Others may want to test so the program can
clean up and leave its files in a sane state. Such cleanup code must of
course be written without further allocations.

Helge Hafting

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/