3 ms·
The reason for not checking malloc is that it's most likely to kill your program instead of returning a failed allocation
by raverbashing 9y ago
The reason for not checking malloc is that it's most likely to kill your program instead of returning a failed allocation
- icebraining 9y agoWhy would a system do that? Either it overcommits, in which case the malloc won't fail (programs get killed only when they try to actually use the memory) or it doesn't, in which case there's no reason to kill it.
- raverbashing 9y agohttps://www.memset.com/docs/additional-information/oom-killer/ https://www.memset.com/docs/additional-information/oom-kille...
- icebraining 9y agoYes, I know about the OOM killer, but it doesn't trigger when you malloc(), only when you actually try to use the memory. In fact, that's the point of the OOM killer: since many applications allocate more memory than they actually need, Linux lets them allocate more memory than what is in fact available, and only kills 'em off when the bluff fails.
- megous 9y agoThe program will crash on null pointer dereference most likely. Malloc will not abort. Some libraries (like glib2) wrap malloc so that it aborts on failure, but standard malloc will never crash.
- alacombe 9y agoin the kernel, it will kill your machine or create exploitable security holes. Check your malloc(3).