Hi,

While trying to fix some other font-related memory leaks, I came across a few issues. They don't plug the major leaks we're seeing, but are still worth fixing...

Francis


2007-04-11  Francis Kung  <[EMAIL PROTECTED]>

        * native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c
        (Java_gnu_java_awt_peer_gtk_FreetypeGlyphVector_getGlyphs): Avoid 
unneeded
        object reference.
        * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c
        (Java_gnu_java_awt_peer_gtk_GdkFontPeer_getFontMetrics): Unlock font.
        (Java_gnu_java_awt_peer_gtk_GdkFontPeer_setFont): Remove redundant 
checks.
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c,v
retrieving revision 1.6
diff -u -r1.6 gnu_java_awt_peer_gtk_FreetypeGlyphVector.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c	2 Apr 2007 21:28:59 -0000	1.6
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c	11 Apr 2007 20:56:24 -0000
@@ -145,17 +145,21 @@
   	    if (pango_fc_font_has_char(default_font, cpvals[i]))
   	      {
   	        current_font = default_font;
+            g_object_ref(current_font);
   	      }
   	    else
   	      {
   	        current_font = (PangoFcFont*)pango_fontset_get_font(pfs, cpvals[i]);
   	      }
   	  }
+  	else
+      {
+        g_object_ref(current_font);
+      }
   	
   	/* Get glyph, and store both glyph and pointer to font */
     glyphArray[i] = (int)pango_fc_font_get_glyph(current_font,
                                                  (gunichar)cpvals[i]);
-    g_object_ref(current_font);
     fontArray[i] = PTR_TO_JLONG(current_font);
   }
   
Index: native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c
===================================================================
RCS file: /cvsroot/classpath/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c,v
retrieving revision 1.23
diff -u -r1.23 gnu_java_awt_peer_gtk_GdkFontPeer.c
--- native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c	2 Apr 2007 19:39:26 -0000	1.23
+++ native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c	11 Apr 2007 20:56:24 -0000
@@ -169,6 +169,8 @@
     face->underline_position / factory;
   native_metrics[FONT_METRICS_UNDERLINE_THICKNESS] =
     face->underline_thickness / factory;
+    
+  pango_fc_font_unlock_face((PangoFcFont *)pfont->font);
 
   (*env)->ReleaseDoubleArrayElements (env, 
 				      java_metrics, 
@@ -256,6 +258,7 @@
   pfont = (struct peerfont *)NSA_GET_FONT_PTR (env, self);
   g_assert (pfont != NULL);
 
+  /* Clear old font information */
   if (pfont->ctx != NULL)
     g_object_unref (pfont->ctx);
   if (pfont->font != NULL)
@@ -265,6 +268,7 @@
   if (pfont->desc != NULL)
     pango_font_description_free (pfont->desc);
 
+  /* Set new description information */
   pfont->desc = pango_font_description_new ();
   g_assert (pfont->desc != NULL);
 
@@ -280,23 +284,17 @@
     pango_font_description_set_style (pfont->desc, PANGO_STYLE_ITALIC);
 
   pango_font_description_set_size (pfont->desc, size * PANGO_SCALE);
-  if (pfont->ctx == NULL)
-    {
-      ft2_map = PANGO_FT2_FONT_MAP(pango_ft2_font_map_new());
-      pfont->ctx = pango_ft2_font_map_create_context (ft2_map);
-      g_object_unref(ft2_map);
-    }
-
-  g_assert (pfont->ctx != NULL);
   
-  if (pfont->font != NULL)
-    {
-      g_object_unref (pfont->font);
-      pfont->font = NULL;
-    }
+  /* Create new context */
+  ft2_map = PANGO_FT2_FONT_MAP(pango_ft2_font_map_new());
+  pfont->ctx = pango_ft2_font_map_create_context (ft2_map);
+  g_object_unref(ft2_map);
+  g_assert (pfont->ctx != NULL);
   
   pango_context_set_font_description (pfont->ctx, pfont->desc);
   pango_context_set_language (pfont->ctx, gtk_get_default_language());
+  
+  /* Create new fontset and default font */
   pfont->set = pango_context_load_fontset(pfont->ctx, pfont->desc,
   										  gtk_get_default_language());
   pfont->font = pango_context_load_font (pfont->ctx, pfont->desc);

Reply via email to