3 ms·
IMHO checking the return value is only useful if you can actually do something about it. For example, you might want to gracefully write a database to disk bef
by Retr0spectrum 10y ago
IMHO checking the return value is only useful if you can actually do something about it.
For example, you might want to gracefully write a database to disk before terminating the program.
It's definitely bad practice, but if you run out of memory during the initialisation of a program, quitting with a segfault is a fairly reasonable error. Of course, catching the error and printing something meaningful would be much better, but if you're in a rush to get something to work for a personal project it's not much of an issue.
- thedjinn 10y agoThe article states that malloc only fails when you run out of virtual address space, which is basically never going to happen if you're on a 64 bit architecture. So you can go for good practice and check all your mallocs for failure, but if the failure never happens why bother?
- bluejekyll 10y agoAlternatively you could throw in a wait/loop and then the program would recover if memory becomes available. Though, that might never happen...
- loeg 10y agoAgreed. The more expected case would be: your httpd is already handling XXX million clients, but the next one comes in and you fail to malloc a tracking structure. Closing the connection and dropping the one client makes more sense than aborting the daemon and dropping all clients.