j_e_f_f_g wrote:It's a total fallacy programmers have that malloc() won't return 0 due to the OOM.
Yes. It's a fallacy that malloc won't return 0. If malloc deduces that there's no way it can fullfill a request, for example due to memory fragmentation, exceeding a ulimit setting (or other mem management settings, such as overcommit_memory), etc, then malloc will return 0.raboof wrote:Uh, no.
http://stackoverflow.com/questions/2248 ... -uses-over
http://voices.canonical.com/jussi.pakka ... -and-linux
http://compgroups.net/comp.unix.program ... ull/471850
The key word being "might". You do realize that you're tacitly admitting that my above statement is true?raboof wrote:On Linux, due to memory overcommit, malloc() might not return NULL even if there's insufficient memory to back your malloc().
That is not what I wrote. Reread my text which you quoted.raboof wrote:allocating chunks of memory on a machine that doesn't have them available doesn't always make malloc() return NULL - which j_e_f_f_g above claimed was a 'total fallacy'.
And I stand by my claim that it should always be done, and that assumptions it's safe/pointless not to do it are incorrect.raboof wrote:Therefore I stand by my earlier claim that checking the return value of malloc() for a small number of small allocations is unlikely to improve the stability of your application when running on a typical Linux system.
