-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added malloc return check #579
Conversation
In this case, the program should crash immediately, it should not be tolerant of this |
Not really, malloc can return valid pointers on other function run. (For example if other program with huge ram impact crashed). In all cases that behavior should be processed, maybe not by false return, but exit(ERR_BAD_ALLOC). |
Broke branch by accident |
This is wrong in any case, out of memory errors are now mixed in with the others without any indication of a real problem, and at some point in time the program, when the memory ends completely, will silently stop working. Moreover, if you look closely at where you made changes, you will notice that most of the modified functions are called at startup - lack of memory during a startup should absolutely not be tolerated, no "for example if other program with huge ram impact crashed" will help, you will never go back there. |
How about other option - exit(ERR_BAD_ALLOC) or any other code to indicate memory error? Cause main problem for me is not handled malloc nulls for user in runtime. |
notice that i changed pr due lack of github interface using experience |
💭 Do you care for the advice “Do not dereference null pointers”? |
It is very important if you write a piece of code that others will depend on, so you don't create unsolvable problems for the developers. If you write an application it is still important, and almost nothing less, but the handling of such errors needs to be more thought out in general, and not just an silent exit from an important procedure without any indication like proposed here, which will lead to weird behaviour from the user perspective. |
🔮 Can you get further development ideas from recommendations by Matthew Wilson? |
Malloc can return null if it can't get memory from os