Skip to content
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

Closed
wants to merge 4 commits into from
Closed

Conversation

EgorWeders
Copy link
Contributor

Malloc can return null if it can't get memory from os

@krlvm
Copy link

krlvm commented Aug 20, 2024

In this case, the program should crash immediately, it should not be tolerant of this

@EgorWeders
Copy link
Contributor Author

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).

@EgorWeders
Copy link
Contributor Author

Broke branch by accident

@krlvm
Copy link

krlvm commented Aug 21, 2024

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).

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.

@EgorWeders
Copy link
Contributor Author

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).

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.

@EgorWeders
Copy link
Contributor Author

EgorWeders commented Aug 21, 2024

notice that i changed pr due lack of github interface using experience

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants