Although this post is very old, I'd like to add the following.
When resources (like memory or disk) are scarse, the program environment becomes unreliable.
I was testing border conditions with a simple program that requested many small chunks of memory until it failed. It was supposed to print a message to a file when no more memory was available (detected through malloc() return value). The program could not write the message to the log file (which was already open) and failed in fprintf() I imagine because fprintf() needed still more memory to work.
The other resource I tested was to fill the disk with small files. When reaching the limit, I could create files of size greater than the space available (they were smaller than cluster size).
I concluded that you can issue a message "out of memory" or "out of disk" if you request a good chunk of either resource, and there is plenty of it, but not if the system is very taxed and you make a request.
So, making a memory request for a link node
struct linkNode
{
int elem;
struct linkNode *next;
} (size is just two words)
and malloc() returns 0? Don't worry, be happy and just exit(-1).
Regards,
Simon.