2 ms·
Allocating memory when there is no available addresses does not reliably result in a seg fault in C?
by willis936 6y ago
Allocating memory when there is no available addresses does not reliably result in a seg fault in C?
- pjmlp 6y agoNot at, depends on the OS. It should return NULL, but not necessarly depending on the OS. For example in Linux it will always return a pointer to memory that is yet to be allocated, it is when you touch the memory for the first time that Linux via the MMU trap, then goes around and actually makes the memory segment available, by then it is too late if the system is running low on memory. https://man7.org/linux/man-pages/man3/malloc.3.html https://man7.org/linux/man-pages/man3/malloc.3.html That is why there is such a thing as OOM daemon on Linux. Secondly, memory leaks like those caused by double free lead to the corruption of the memory allocator, thus whatever happens depends pretty much on the implementation being used.