-
-
Notifications
You must be signed in to change notification settings - Fork 316
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
r.out.png: fix consecutive fclose calls on same pointer #4214
Conversation
This patch fixes two issues: 1. In one of the code paths, we are calling fclose on a file pointer which could potentially be NULL. Doing that would lead to undefined behavior. Check if a file pointer is NULL before closing it. 2. If we call fclose on same file pointer twice, in the second instance we could be closing file descriptor allocated to some other file, which typically happens to a freed descriptor. This issue was found by using cppcheck tool. Signed-off-by: Mohana Datta Yelugoti <ymdatta.work@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with the PR. I would want some feedback on if it is the correct pattern to be autonomous on future reviews of this kind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I my thoughts:
- Default value is set.
- NULL is the right default for FILE.
- fclose requires a check.
What Cppcheck does not see is that G_fatal_error does not return, so the later fclose calls will not happen. I'm not sure what is better here, try to configure, try to provide attributes to the function, or simply apply the best practice (close and set to NULL) regardless of the fact that it is not need. I lean towards the best practice as it is seems the simplest, however providing more info about the function to the compilers or the linters seems good long-term strategy.
Missed this by the second. The only place where it would have made any (if ever so little) sense to reset Lines 372 to 373 in 917ba58
Other than that note, this was good to go. |
The last |
I will push another small patch adding |
This patch fixes two issues: 1. In one of the code paths, we are calling fclose on a file pointer which could potentially be NULL. Doing that would lead to undefined behavior. Check if a file pointer is NULL before closing it. 2. If we call fclose on same file pointer twice, in the second instance we could be closing file descriptor allocated to some other file, which typically happens to a freed descriptor. This issue was found by using cppcheck tool. Signed-off-by: Mohana Datta Yelugoti <ymdatta.work@gmail.com>
This patch fixes two issues:
In one of the code paths, we are calling fclose on a file pointer which could potentially be NULL. Doing that would lead to undefined behavior. Check if a file pointer is NULL before closing it.
If we call fclose on same file pointer twice, in the second instance we could be closing file descriptor allocated to some other file, which typically happens to a freed descriptor.
This issue was found by using cppcheck tool.
Additional information:
Tool's output after applying the patch