[OpenJDK 2D-Dev] What is the point of CloseTTFontFileFunc?

Andrew Dinn adinn at redhat.com
Fri Dec 19 11:08:36 UTC 2014

Hi All,

I am looking at a problem Red Hat customers have reported with True Type
fonts where they are seeing a Hotspot crash using JDK7. the problem
relates to the use of TT font scalers and, in particular to code called
under native methods initNativeScaler and disposeNativeScaler of class

While investigating this I looked at the stream close function
CloseTTFontFileFunc provided for the scaler in freetypeScaler.c and was
rather confused as to what it was supposed to achieve. n.b. the code
below from the release version of Icedtea7 which caused the problem
appears still to exist unchanged in the latest jdk7u, jdk8u and jdk9).

/* NB: is it ever called? */
static void CloseTTFontFileFunc(FT_Stream stream) {
    FTScalerInfo *scalerInfo = (FTScalerInfo *) stream->pathname.pointer;
    JNIEnv* env = scalerInfo->env;
    jclass tmpClass = (*env)->FindClass(env, "sun/font/TrueTypeFont");
    jfieldID platNameField =
         (*env)->GetFieldID(env, tmpClass, "platName",
    jstring platName = (*env)->GetObjectField(env,
    const char *name = JNU_GetStringPlatformChars(env, platName, NULL);
    JNU_ReleaseStringPlatformChars(env, platName, name);

Is there any point in calling JNU_GetStringPlatformChars and then
JNU_ReleaseStringPlatformChars? This appears simply to malloc a copy of
the platname string, albeit perhaps with some multibyte chars replaced
with '?', and then to immediately free the allocated string. Is there
any good reason for this?


Andrew Dinn

More information about the 2d-dev mailing list