On Mon, 28 Aug 2023 21:28:01 GMT, Kevin Rushforth <[email protected]> wrote:
>> modules/javafx.graphics/src/main/native-glass/gtk/GlassApplication.cpp line
>> 270:
>>
>>> 268: // we release this context in call_runnable
>>> 269: } else {
>>> 270: fprintf(stderr, "malloc failed in
>>> GtkApplication__1submitForLaterInvocatio\n");
>>
>> if the malloc above failed, I would think there might be very serious errors
>> hence maybe this should be propagated to the Java layer, or throw the
>> relevant memory exception?
>
> That's a good question. Since this is a void method (thus there is no way to
> signal an error), the ideal thing would be to throw an `OutOfMemoryError`
> before returning, but if a malloc of this small size were to fail, we might
> not even be able to create the OOME. Not sure it's worth it in this case.
> What do you think?
I agree a crash due to a null pointer is not desired, as that gives very little
info to the developer.
If that malloc fails, it is an indication that there is a major chance that we
are in serious trouble. In that case, simply printing something (which could
fail as well if there is that limited memory) and not informing the caller will
most likely just postpone the crash.
Unless we can free some memory immediately, I think it might be good if we can
try to exit gracefully. The drawback of this is that *if* there is a trivial
way to free memory and the native code was just about to invoke free() on a big
memory chunk, we are exiting without a good reason (although I think this
scenario is unlikely).
-------------
PR Review Comment: https://git.openjdk.org/jfx/pull/1223#discussion_r1308385194