RFR: JDK-8313164: src/java.desktop/windows/native/libawt/windows/awt_Robot.cpp GetRGBPixels adjust releasing of resources [v2]

Alexey Ivanov aivanov at openjdk.org
Thu Jul 27 19:59:55 UTC 2023


On Wed, 26 Jul 2023 11:59:06 GMT, Matthias Baesken <mbaesken at openjdk.org> wrote:

>> 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.
>
> Matthias Baesken has updated the pull request incrementally with one additional commit since the last revision:
> 
>   adjust checks and calculation of numPixels

src/java.desktop/windows/native/libawt/windows/awt_Robot.cpp line 207:

> 205:         ::DeleteDC(hdcScreen);
> 206:         throw std::bad_alloc();
> 207:     }

I wonder if we can catch std::bad_alloc releases the resources and 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.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/15038#discussion_r1276761238



More information about the client-libs-dev mailing list