logoalt Hacker News

sidewndr46last Friday at 8:50 PM3 repliesview on HN

Do any of the settings actually result in "malloc" or a similar function returning NULL?


Replies

LordGreylast Friday at 8:57 PM

malloc() and friends may always return NULL. From the man page:

If successful, calloc(), malloc(), realloc(), reallocf(), valloc(), and aligned_alloc() functions return a pointer to allocated memory. If there is an error, they return a NULL pointer and set errno to ENOMEM.

In practice, I find a lot of code that does not check for NULL, which is rather distressing.

show 2 replies
themafiayesterday at 4:36 AM

malloc() is an interface. There are many implementations.

fulafelyesterday at 9:42 AM

Yes.