On Fri, 16 Oct 2026 21:24:21 GMT, Phil Race <[email protected]> wrote:

>> The gcc static analyzer reports this issue :
>> 
>> `jdk/src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c:1195:1: 
>> warning: leak of 'asd.configs' [CWE-401] [-Wanalyzer-malloc-leak]`
>> 
>> In Java_sun_awt_X11GraphicsConfig_init(JNIEnv *env, jobject this, jint 
>> visualNum, jint screen)
>> we have this coding
>> 
>> 
>>     AwtScreenData asd = x11Screens[screen];
>>     ...
>>     if (asd.numConfigs == 0) {
>>         getAllConfigs(env, screen, &asd); // line 1163 — seems we fill the 
>> 'local copy' asd only
>>     }
>> 
>> 
>> So at the end of function Java_sun_awt_X11GraphicsConfig_init, the leask of 
>> some asd field is reported.
>> (maybe we do not call these init methods very often, so it might be a rare 
>> issue)
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c line 1156:
> 
>> 1154: 
>> 1155:     AwtGraphicsConfigData *adata = NULL;
>> 1156:     AwtScreenData *asd = &x11Screens[screen];
> 
> I do not understand how this changes anything ...

If we use the 'real' object reference in the x11Screens array and not a local 
variable like AwtScreenData asd, I think we should avoid the leak. Or do I miss 
something?

> src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c line 1191:
> 
>> 1189:                              adata->awt_visInfo.visual,
>> 1190:                              depth, ZPixmap, 0, NULL, 1, 1, 32, 0);
>> 1191:     if (tempImage == NULL) {
> 
> whilst throwing an exception is better than a crash, why did you decide to 
> throw rather than just return.

Because in another sanity check a few lines above (line 1176) we do the same, 
so I thought it might be consistent.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/33405#discussion_r4303085254
PR Review Comment: https://git.openjdk.org/jdk/pull/33405#discussion_r4303074158

Reply via email to