-
Notifications
You must be signed in to change notification settings - Fork 61
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
pixz doesn't check for out-of-memory #8
Comments
Thanks for the bug report. You're correct in the strict sense, if the realloc fails, pixz will crash. Unfortunately, since pixz doesn't do any checking for out-of-memory conditions, ANY malloc/realloc failure will cause a crash. I guess this could be 'fixed' by just going through the code and calling die() if any malloc fails, but that doesn't really help. Ideally we'd preallocate all memory, but that would be a huge and invasive change. Even more-ideally, we'd also try to prevent the system from swapping. |
I think, it is good practice to use a tool like the abovementioned cppcheck. I am working on adding this to travis. |
@vasi I have prepared a pull request that both adds a cppcheck test to the source directory (good to have this anyway) and fixes this issue by implementing a check on the result of the realloc function call. If you are OK with this, please let me know or merge the pull request #42 yourself. I am asking you specifically because you have shown hesitance on the issue in a previous comment. IMHO, in the end, it is always better to give the end-user a reasonable error message than letting pixz error out by itself while dereferencing NULL. |
@vasi ping |
Sorry, I didn't see this earlier. I think it's useful, you're certainly right that it's better to provide an error than just crash. Feel free to commit! I do want to still push for a real solution, though:
|
I have added a TODO comment so we can address this later. We should probably open a new issue to address OOM prevention and recovery as a future feature. I will do this. |
SO pixz still has OOM issue? |
OOM is usually considered to be a fatal error, because, in most cases, there is nothing you can do about it but crash. Often, applications do not even handle this error and let it fall through to the application caller, e.g. the terminal / shell process. Being able to prevent OOM or even recover from it highly depends on the application. Whether or not we can do this at all in a sane way must be researched. We will keep you up-to-date on this progress in #44. What I did here to solve this issue, is just checking the |
cppcheck complains as follows
I didn't follow the code outside that function, but just looking at that line it does look like that could be a problem if realloc returns NULL.
The text was updated successfully, but these errors were encountered: