[OpenJDK 2D-Dev] RFR: JDK-8260432: allocateSpaceForGP in freetypeScaler.c might leak memory

Aleksey Shipilev shade at openjdk.java.net
Wed Jan 27 12:04:42 UTC 2021


On Wed, 27 Jan 2021 11:59:29 GMT, Matthias Baesken <mbaesken at openjdk.org> wrote:

>> src/java.desktop/share/native/libfontmanager/freetypeScaler.c line 1290:
>> 
>>> 1288: 
>>> 1289:     /* failure if any of mallocs failed */
>>> 1290:     if (gpdata->pointTypes == NULL || gpdata->pointCoords == NULL)
>> 
>> I think it would be cleaner to free the remaining allocations on the failing path:
>> 
>> if (gpdata->pointTypes == NULL || gpdata->pointCoords == NULL) {
>>    if (gpdata->pointTypes != NULL)  free(gpdata->pointTypes);
>>    if (gpdata->pointCoords != NULL) free(gpdata->pointCoords);
>>    return 0;
>> } else {
>>    return 1;
>> }
>
> Then we would free   as well  for the realloc code path
>     } else {
>         /* do we have enough space? */
>     ...
>     }
> Is this okay?

Yes, I think that is better: `realloc` can fail as well, and we don't want to leak those?

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

PR: https://git.openjdk.java.net/jdk/pull/2250


More information about the 2d-dev mailing list