On Wed, 27 Jan 2021 11:41:48 GMT, Aleksey Shipilev <sh...@openjdk.org> wrote:
>> The function AllocateSpaceForGP in freetypeScaler.c calls potentially 2 >> times malloc ; however the memory is not always freed correctly in case of >> errors. >> See also the related sonar issue : >> https://sonarcloud.io/project/issues?id=shipilev_jdk&languages=c&open=AXck8B_SBBG2CXpcngxr&resolved=false&severities=BLOCKER&types=BUG > > 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? ------------- PR: https://git.openjdk.java.net/jdk/pull/2250