From ce50c4e91173eee9c516be3da85578e755ff9234 Mon Sep 17 00:00:00 2001 From: Zhengyu Gu Date: Mon, 11 Apr 2022 08:56:28 -0400 Subject: [PATCH 1/3] v0 --- src/java.desktop/unix/native/common/awt/fontpath.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/java.desktop/unix/native/common/awt/fontpath.c b/src/java.desktop/unix/native/common/awt/fontpath.c index fd28f5c0ea6dc..5c2c620e4f12d 100644 --- a/src/java.desktop/unix/native/common/awt/fontpath.c +++ b/src/java.desktop/unix/native/common/awt/fontpath.c @@ -523,6 +523,7 @@ typedef FcFontSet* (*FcFontSortFuncType)(FcConfig *config, FcResult *result); typedef FcCharSet* (*FcCharSetUnionFuncType)(const FcCharSet *a, const FcCharSet *b); +typedef FcCharSet* (*FcCharSetDestroyFuncType)(FcCharSet *fcs); typedef FcChar32 (*FcCharSetSubtractCountFuncType)(const FcCharSet *a, const FcCharSet *b); @@ -808,6 +809,7 @@ Java_sun_font_FontConfigManager_getFontConfig FcFontSortFuncType FcFontSort; FcFontSetDestroyFuncType FcFontSetDestroy; FcCharSetUnionFuncType FcCharSetUnion; + FcCharSetDestroyFuncType FcCharSetDestroy; FcCharSetSubtractCountFuncType FcCharSetSubtractCount; FcGetVersionFuncType FcGetVersion; FcConfigGetCacheDirsFuncType FcConfigGetCacheDirs; @@ -887,6 +889,8 @@ Java_sun_font_FontConfigManager_getFontConfig (FcFontSetDestroyFuncType)dlsym(libfontconfig, "FcFontSetDestroy"); FcCharSetUnion = (FcCharSetUnionFuncType)dlsym(libfontconfig, "FcCharSetUnion"); + FcCharSetDestroy = + (FcCharSetDestroyFuncType)dlsym(libfontconfig, "FcCharSetDestroy"); FcCharSetSubtractCount = (FcCharSetSubtractCountFuncType)dlsym(libfontconfig, "FcCharSetSubtractCount"); @@ -902,6 +906,7 @@ Java_sun_font_FontConfigManager_getFontConfig FcPatternGetCharSet == NULL || FcFontSetDestroy == NULL || FcCharSetUnion == NULL || + FcCharSetDestroy == NULL || FcGetVersion == NULL || FcCharSetSubtractCount == NULL) {/* problem with the library: return.*/ closeFontConfig(libfontconfig, JNI_FALSE); @@ -1100,7 +1105,11 @@ Java_sun_font_FontConfigManager_getFontConfig } else { if ((*FcCharSetSubtractCount)(charset, unionCharset) > minGlyphs) { - unionCharset = (* FcCharSetUnion)(unionCharset, charset); + FcCharSet *currentUnionSet = unionCharset; + unionCharset = (* FcCharSetUnion)(currentUnionSet, charset); + if (currentUnionSet != charset) { + (*FcCharSetDestroy)(currentUnionSet); + } } else { continue; } From 92ed6a784de2762efb827a3e170da9fbe9869eeb Mon Sep 17 00:00:00 2001 From: Zhengyu Gu Date: Fri, 29 Apr 2022 08:37:53 -0400 Subject: [PATCH 2/3] Andrew's comment --- src/java.desktop/unix/native/common/awt/fontpath.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/java.desktop/unix/native/common/awt/fontpath.c b/src/java.desktop/unix/native/common/awt/fontpath.c index 5c2c620e4f12d..ef78167e87b38 100644 --- a/src/java.desktop/unix/native/common/awt/fontpath.c +++ b/src/java.desktop/unix/native/common/awt/fontpath.c @@ -972,6 +972,7 @@ Java_sun_font_FontConfigManager_getFontConfig FcChar8 **family, **styleStr, **fullname, **file; jarray fcFontArr = NULL; FcCharSet *unionCharset = NULL; + FcCharSet *prevUnionCharset = NULL; fcCompFontObj = (*env)->GetObjectArrayElement(env, fcCompFontArray, i); fcNameStr = @@ -1105,11 +1106,11 @@ Java_sun_font_FontConfigManager_getFontConfig } else { if ((*FcCharSetSubtractCount)(charset, unionCharset) > minGlyphs) { - FcCharSet *currentUnionSet = unionCharset; - unionCharset = (* FcCharSetUnion)(currentUnionSet, charset); - if (currentUnionSet != charset) { - (*FcCharSetDestroy)(currentUnionSet); + unionCharset = (* FcCharSetUnion)(unionCharset, charset); + if (prevUnionCharset != NULL) { + (*FcCharSetDestroy)(prevUnionCharset); } + prevUnionCharset = unionCharset; } else { continue; } @@ -1128,6 +1129,11 @@ Java_sun_font_FontConfigManager_getFontConfig } } + // Release last instance of CharSet union + if (prevUnionCharset != NULL) { + (*FcCharSetDestroy)(prevUnionCharset); + } + /* Once we get here 'fontCount' is the number of returned fonts * we actually want to use, so we create 'fcFontArr' of that length. * The non-null entries of "family[]" etc are those fonts. From 2c74ef962235e7fee595b32c4076c622e8ee7b7f Mon Sep 17 00:00:00 2001 From: Zhengyu Gu Date: Mon, 9 May 2022 15:39:17 -0400 Subject: [PATCH 3/3] Cleanup at early return --- src/java.desktop/unix/native/common/awt/fontpath.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/java.desktop/unix/native/common/awt/fontpath.c b/src/java.desktop/unix/native/common/awt/fontpath.c index ef78167e87b38..df35e78e6e187 100644 --- a/src/java.desktop/unix/native/common/awt/fontpath.c +++ b/src/java.desktop/unix/native/common/awt/fontpath.c @@ -1086,6 +1086,9 @@ Java_sun_font_FontConfigManager_getFontConfig free(file); (*FcPatternDestroy)(pattern); (*FcFontSetDestroy)(fontset); + if (prevUnionCharset != NULL) { + (*FcCharSetDestroy)(prevUnionCharset); + } closeFontConfig(libfontconfig, JNI_FALSE); if (locale) { (*env)->ReleaseStringUTFChars(env, localeStr, (const char*)locale);