On Tue, 8 Mar 2022 09:18:01 GMT, Sergey Bylokhov <s...@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? Good catch! Elsewhere in this file IS_NULL is always used to check NewStringUTF, so the existing code was inconsistent in checking for a pending exception. Checking for NULL and checking for a pending exception are logically equivalent as long as the passed in pointer is not NULL. ------------- PR: https://git.openjdk.java.net/jdk/pull/7691