RFR: 8292214: Memory leak in getAllConfigs of awt_GraphicsEnv.c:386 [v2]

Phil Race prr at openjdk.org
Fri Sep 30 22:00:23 UTC 2022


On Thu, 22 Sep 2022 04:22:34 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

>> Alisen Chung has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   changed loop end condition to ind-1
>
> src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c line 578:
> 
>> 576:             if (graphicsConfigs[i] != 0) {
>> 577:                 free(graphicsConfigs[i]);
>> 578:             }
> 
> It seems  `screenDataPtr->numConfigs` is updated only when `success = JNI_TRUE` and here we are checking if `success != JNI_TRUE` condition, so amnot sure if we will be getting the correct updated configs number.
> I think condition should be `i< ind-1` which is updated before every allocation, but it should be verified.

I think "nConfig" would have been the better value to use.
Look at how the array is allocated and that it is zeroed out
   nConfig = n8p + n12p + n8s + n8gs + n8sg  + n1sg + nTrue + 1;
    graphicsConfigs = (AwtGraphicsConfigDataPtr *)
        calloc(nConfig, sizeof(AwtGraphicsConfigDataPtr));

So it should always be safe.

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

PR: https://git.openjdk.org/jdk/pull/10378



More information about the client-libs-dev mailing list