-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
JDK-8313164: src/java.desktop/windows/native/libawt/windows/awt_Robot.cpp GetRGBPixels adjust releasing of resources #15038
Conversation
👋 Welcome back mbaesken! A progress list of the required criteria for merging this PR into |
Webrevs
|
One additional idea - in case of failing IS_SAFE* checks (leading to the throw astd::bad_alloc) , should we add some tracing to make clear what went wrong ? We have |
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.
Okay. Did you find this with SonarCloud?
Since this is c++, it may be simpler to use RAII for this. Up to you though, the patch is also fine in its current form.
@MBaesken This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 9 new commits pushed to the
Please see this link for an up-to-date comparison between the source branch of this pull request and the ➡️ To integrate this PR with the above commit message to the |
Hi Thomas , I just found those while looking at some other resource alloc/freeing, no Sonatype or similar was used. Regarding RAII , not sure if something like this is used in the awt native code (or are there some good examples in awt native code?) . So I better keep it as it is, to be consistent with the codebase around it. |
/integrate |
Going to push as commit b7545a6.
Your commit was automatically rebased without conflicts. |
if (!IS_SAFE_SIZE_MUL(BYTES_PER_PIXEL, numPixels)) { | ||
::DeleteObject(hbitmap); | ||
::DeleteDC(hdcMem); | ||
::DeleteDC(hdcScreen); | ||
throw std::bad_alloc(); | ||
} |
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 wonder if we can catch std::bad_alloc
to release the resources and to re-throw the exception.
Since a C++ exception is thrown, using try-catch for clean-up seems reasonable, this would avoid duplicating the clean-up code in three places or so.
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.
Hi Alexey, probably we could do this. Do you think it is worth the effort (we would have a big try catch block instead, but would centralize the ::Delete* calls) ?
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.
Since you've already integrated, it's not worth redoing in my opinion.
Error handling in C and C++ code is always prone to repetitive sequence of calls; in this particular case exceptions are already used, and it looks that handling that exception could have had a benefit of reducing code duplication.
In src/java.desktop/windows/native/libawt/windows/awt_Robot.cpp GetRGBPixels we release some resources at the end of the function by calling DeleteObject/DeleteDC. This is recommended by the MS API docs.
However this should be done as well in some early leaving with throw that can occur in this function.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15038/head:pull/15038
$ git checkout pull/15038
Update a local copy of the PR:
$ git checkout pull/15038
$ git pull https://git.openjdk.org/jdk.git pull/15038/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 15038
View PR using the GUI difftool:
$ git pr show -t 15038
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15038.diff
Webrev
Link to Webrev Comment