RFR: 8282628: Potential memory leak in sun.font.FontConfigManager.getFontConfig()
Sergey Bylokhov
serb at openjdk.java.net
Tue Mar 8 09:24:08 UTC 2022
On Fri, 4 Mar 2022 13:25:12 GMT, Zhengyu Gu <zgu at openjdk.org> wrote:
> Please review this small patch that fixes a potential memory leak that exception return fails to release allocated `cacheDirs`
>
> Test:
>
> - [x] jdk_desktop on Linux x86_64
src/java.desktop/unix/native/common/awt/fontpath.c line 938:
> 936: while ((cnt < max) && (cacheDir = (*FcStrListNext)(cacheDirs))) {
> 937: jstr = (*env)->NewStringUTF(env, (const char*)cacheDir);
> 938: JNU_CHECK_EXCEPTION_AND_CLEANUP(env, (*FcStrListDone)(cacheDirs));
I think you do not need to create an additional macro here, just inline it and call "(*FcStrListDone)(cacheDirs);" directly. Something like:
if (IS_NULL(jstr) {
(*FcStrListDone)(cacheDirs);
return;
}
Note that the "IS_NULL" is used in this file after NewStringUTF. Any objections?
src/java.desktop/unix/native/common/awt/fontpath.c line 940:
> 938: JNU_CHECK_EXCEPTION_AND_CLEANUP(env, (*FcStrListDone)(cacheDirs));
> 939:
> 940: (*env)->SetObjectArrayElement(env, cacheDirArray, cnt++, jstr);
Probably we should add the check+cleanup after the SetObjectArrayElement? Otherwise, we may call NewStringUTF while an exception is raised by the SetObjectArrayElement.
-------------
PR: https://git.openjdk.java.net/jdk/pull/7691
More information about the core-libs-dev
mailing list