6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread
authorigor
Wed, 17 Dec 2008 22:00:37 +0300
changeset 2369 b58cdc0321f5
parent 2368 5a872c1edd4f
child 2370 bdaf8cd4253f
6761791: Crash in the FontManager code due to use of JNIEnv saved by another thread Reviewed-by: bae, prr
jdk/src/share/native/sun/font/freetypeScaler.c
--- a/jdk/src/share/native/sun/font/freetypeScaler.c	Fri Dec 12 17:38:14 2008 +0300
+++ b/jdk/src/share/native/sun/font/freetypeScaler.c	Wed Dec 17 22:00:37 2008 +0300
@@ -394,12 +394,14 @@
     scalerInfo->env = env;
     scalerInfo->font2D = font2D;
 
-    FT_Set_Transform(scalerInfo->face, &context->transform, NULL);
+    if (context != NULL) {
+        FT_Set_Transform(scalerInfo->face, &context->transform, NULL);
 
-    errCode = FT_Set_Char_Size(scalerInfo->face, 0, context->ptsz, 72, 72);
+        errCode = FT_Set_Char_Size(scalerInfo->face, 0, context->ptsz, 72, 72);
 
-    if (errCode == 0) {
-        errCode = FT_Activate_Size(scalerInfo->face->size);
+        if (errCode == 0) {
+            errCode = FT_Activate_Size(scalerInfo->face->size);
+        }
     }
 
     return errCode;
@@ -885,6 +887,14 @@
         JNIEnv *env, jobject scaler, jlong pScaler) {
     FTScalerInfo* scalerInfo = (FTScalerInfo *) jlong_to_ptr(pScaler);
 
+    /* Freetype functions *may* cause callback to java
+       that can use cached values. Make sure our cache is up to date.
+       NB: scaler context is not important at this point, can use NULL. */
+    int errCode = setupFTContext(env, scaler, scalerInfo, NULL);
+    if (errCode) {
+        return;
+    }
+
     freeNativeResources(env, scalerInfo);
 }
 
@@ -932,12 +942,21 @@
         JNIEnv *env, jobject scaler, jlong pScaler, jchar charCode) {
 
     FTScalerInfo* scalerInfo = (FTScalerInfo *) jlong_to_ptr(pScaler);
+    int errCode;
 
     if (scaler == NULL || scalerInfo->face == NULL) { /* bad/null scaler */
         invalidateJavaScaler(env, scaler, scalerInfo);
         return 0;
     }
 
+    /* Freetype functions *may* cause callback to java
+       that can use cached values. Make sure our cache is up to date.
+       Scaler context is not important here, can use NULL. */
+    errCode = setupFTContext(env, scaler, scalerInfo, NULL);
+    if (errCode) {
+        return 0;
+    }
+
     return FT_Get_Char_Index(scalerInfo->face, charCode);
 }