Yes, you should still check for failures returned by malloc
. In an environment that overcommits memory you will not be able to detect and recover from failures due to the environment running out of physical storage required when you write to parts of the address space that have been allocated to your program by a previous call to malloc
.
However, this is not the only problem that would cause a malloc
to fail in a traditional environment. A request for a particularly large block of memory when the address space of your program has become fragmented may fail even if there is potentially enough total physical memory to satisfy the request. Because there is no contiguous range of free address space malloc
must fail. This type of failure must be signaled by malloc
returning NULL
, whether or not the environment is overcommitting memory.