Additionally, note that even if you do save and test the return value from malloc
, it is nearly impossible to force a malloc
failure, because malloc
does not actually allocate any memory. At the kernel level, the system calls that malloc
uses are simply allocating Page Table Entries (or similar CPU virtual memory assets on "other" CPU architectures) for the memory to be mapped into your process when it is accessed.