-
Notifications
You must be signed in to change notification settings - Fork 438
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
Closing files after opening them. #3285
base: master
Are you sure you want to change the base?
Conversation
Closing files before exiting a program isn't needed. The semantics of MFILE are that if you open() you have to close(). |
Well, the computer does not break, but BOINC is running for a long time and there has been that report on a file descriptor leakage for other installations. If the file does not need to be reopened a few seconds later - just close it and free the resources.
I disagree. A destructor encountering the left-open file should close it. If the semantics of that class suggest otherwise, it should still close it and send a request to stderr to get this fixed. If there is a forwarding of responsibilities to close that file by some copy operator of some sort, then this needs to be catered for. |
In my opinion we should also check the return value of |
I agree with the PRs motivation and intentions but haven't yet verified the logic/code paths. What needs fixing either way is the indentation that currently a bit off. |
There is more to the PR than the closing of files. @davidpanderson is however right that the file-closing concerns are indeed driven by short-lived applications. Feel free to cut that. However, from my POV I do not care if it is a long-running process or a short-running one. Did not even look - otherwise I may not even have submitted it to avoid discussions. I always close what is no longer needed. And free what is no longer needed. ASAP, "P" as in "there is no semantics associated with 'having a lock on a file'". That way the code is also allowed to move into other parts of BOINC. There is no unnecessary context required to understand that part of the code. And I admittely sense some satisfaction over that elegance. |
If you fix the indentation this is ready to be merged. My POV is that closing a file even before ending a short-lived program shows that the developer intentionally thought about where to close the file. The same goes for MFILE. What if a developer forgot about the semantics and didn't close. The destructor would take care of that. |
Codecov Report
@@ Coverage Diff @@
## master #3285 +/- ##
=============================================
+ Coverage 9.27% 22.63% +13.36%
- Complexity 0 756 +756
=============================================
Files 36 101 +65
Lines 5992 7319 +1327
Branches 0 1516 +1516
=============================================
+ Hits 556 1657 +1101
- Misses 5436 5550 +114
- Partials 0 112 +112 |
The indenting should be fine now - typical tabs vs blanks. Isn't there possibly a way to have the auto-indented? |
This patch is with Debian for a really long time, likely to have its origins also in the cppcheck and/or clang runs. Just like PR #3284, this also addresses the reported leaking of file descriptors (#1175).
Anchor: #3260