Index: vte/src/vtexft.c
===================================================================
--- vte.orig/src/vtexft.c	2008-06-21 18:12:02.000000000 -0700
+++ vte/src/vtexft.c	2008-06-21 18:12:08.000000000 -0700
@@ -58,6 +58,9 @@
 
 	gint width, height, ascent;
 	gboolean have_metrics;
+
+	GPtrArray *locked_fonts[2];
+	guint cur_locked_fonts;
 };
 
 struct _vte_xft_data {
@@ -74,8 +77,6 @@
 	Pixmap xpixmap;
 	gint pixmapw, pixmaph;
 	gint scrollx, scrolly;
-	GPtrArray *locked_fonts[2];
-	guint cur_locked_fonts;
 	gboolean has_clip_mask;
 };
 
@@ -133,6 +134,16 @@
 	return TRUE;
 }
 
+static GPtrArray *
+ptr_array_zeroed_new (guint len)
+{
+	GPtrArray *ptr;
+	ptr = g_ptr_array_sized_new (len);
+	while (len--) {
+		g_ptr_array_add (ptr, NULL);
+	}
+	return ptr;
+}
 static struct _vte_xft_font *
 _vte_xft_font_open (GtkWidget *widget, const PangoFontDescription *fontdesc,
 		   VteTerminalAntiAlias antialias)
@@ -147,12 +158,14 @@
 		return NULL;
 	}
 
-	font = g_slice_new (struct _vte_xft_font);
+	font = g_slice_new0 (struct _vte_xft_font);
 	font->ref = 1;
 	font->display = GDK_DISPLAY_XDISPLAY (gtk_widget_get_display (widget));
 	font->patterns = patterns;
 	font->last_pattern = 0;
 	font->have_metrics = FALSE;
+	font->locked_fonts[0] = ptr_array_zeroed_new (1 + font->patterns->len);
+	font->locked_fonts[1] = ptr_array_zeroed_new (1 + font->patterns->len);
 
 	if (font_cache == NULL) {
 		font_cache = g_hash_table_new (
@@ -216,11 +229,12 @@
 }
 
 static XftFont *
-_vte_xft_open_font_for_char (struct _vte_xft_font *font, gunichar c, GPtrArray *locked_fonts)
+_vte_xft_open_font_for_char (struct _vte_xft_font *font, gunichar c)
 {
 	gpointer p = GINT_TO_POINTER (c);
 	guint i, j;
 	XftFont *ftfont;
+	GPtrArray *locked_fonts = font->locked_fonts[font->cur_locked_fonts&1];
 
 	/* Look the character up in the fonts we have. */
 	for (i = 1; i < font->fonts->len; i++) {
@@ -268,10 +282,11 @@
 	return NULL;
 }
 static inline XftFont *
-_vte_xft_font_for_char (struct _vte_xft_font *font, gunichar c, GPtrArray *locked_fonts)
+_vte_xft_font_for_char (struct _vte_xft_font *font, gunichar c)
 {
 	guint i;
 	XftFont *ftfont;
+	GPtrArray *locked_fonts = font->locked_fonts[font->cur_locked_fonts&1];
 
 	/* Check if we have a char-to-font entry for it. */
 	i = GPOINTER_TO_INT (_vte_tree_lookup (
@@ -291,7 +306,7 @@
 			return ftfont;
 		}
 	} else
-		return _vte_xft_open_font_for_char (font, c, locked_fonts);
+		return _vte_xft_open_font_for_char (font, c);
 }
 
 static gint _vte_xft_compute_char_width (struct _vte_xft_font *font, XftFont *ftfont, gunichar c, int columns)
@@ -357,19 +372,34 @@
 }
 
 static void
-_vte_xft_unlock_fonts (struct _vte_xft_data *data)
+_vte_xft_unlock_font (struct _vte_xft_font *font, guint element, gboolean free_array)
 {
-	guint i, j;
-	for (i = 0; i < G_N_ELEMENTS (data->locked_fonts); i++) {
-		for (j = 1; j < data->locked_fonts[i]->len; j++) {
+	guint j, i;
+	i = element & 1;
+
+	if (font->locked_fonts[i] != NULL) {
+		for (j = 1; j < font->locked_fonts[i]->len; j++) {
 			XftFont *ftfont = g_ptr_array_index (
-					data->locked_fonts[i], j);
+					font->locked_fonts[i], j);
 			if (ftfont != NULL) {
 				XftUnlockFace (ftfont);
+				g_ptr_array_index (
+					font->locked_fonts[i], j) = NULL;
 			}
 		}
-		g_ptr_array_free (data->locked_fonts[i], TRUE);
-		data->locked_fonts[i] = NULL;
+		if (free_array) {
+			g_ptr_array_free (font->locked_fonts[i], TRUE);
+			font->locked_fonts[i] = NULL;
+		}
+	}
+}
+
+static void
+_vte_xft_unlock_fonts (struct _vte_xft_font *font)
+{
+	guint i;
+	for (i = 0; i < G_N_ELEMENTS (font->locked_fonts); i++) {
+		_vte_xft_unlock_font (font, i, TRUE);
 	}
 }
 static void
@@ -378,7 +408,7 @@
 	struct _vte_xft_data *data;
 	data = (struct _vte_xft_data*) draw->impl_data;
 	if (data->font != NULL) {
-		_vte_xft_unlock_fonts (data);
+		_vte_xft_unlock_fonts (data->font);
 		_vte_xft_font_close (data->font);
 	}
 	if (data->pixmap != NULL) {
@@ -406,8 +436,6 @@
 _vte_xft_start (struct _vte_draw *draw)
 {
 	GdkDrawable *drawable;
-	GPtrArray *locked_fonts;
-	guint i;
 
 	struct _vte_xft_data *data;
 	data = (struct _vte_xft_data*) draw->impl_data;
@@ -437,18 +465,7 @@
 	}
 	g_assert (data->display == data->font->display);
 
-	locked_fonts = data->locked_fonts [++data->cur_locked_fonts&1];
-	if (locked_fonts != NULL) {
-		guint cnt=0;
-		for (i = 1; i < locked_fonts->len; i++) {
-			XftFont *ftfont = g_ptr_array_index (locked_fonts, i);
-			if (ftfont != NULL) {
-				XftUnlockFace (ftfont);
-				g_ptr_array_index (locked_fonts, i) = NULL;
-				cnt++;
-			}
-		}
-	}
+	_vte_xft_unlock_font (data->font, ++data->font->cur_locked_fonts&1, FALSE);
 }
 
 static void
@@ -614,16 +631,6 @@
 	XFreeGC (data->display, gc);
 }
 
-static GPtrArray *
-ptr_array_zeroed_new (guint len)
-{
-	GPtrArray *ptr;
-	ptr = g_ptr_array_sized_new (len);
-	while (len--) {
-		g_ptr_array_add (ptr, NULL);
-	}
-	return ptr;
-}
 static void
 _vte_xft_set_text_font (struct _vte_draw *draw,
 		       const PangoFontDescription *fontdesc,
@@ -637,7 +644,7 @@
 	ft = _vte_xft_font_open (draw->widget, fontdesc, antialias);
 	if (ft != NULL) {
 		if (data->font != NULL) {
-			_vte_xft_unlock_fonts (data);
+			_vte_xft_unlock_fonts (data->font);
 			_vte_xft_font_close (data->font);
 		}
 		data->font = ft;
@@ -646,8 +653,6 @@
 		return;
 	}
 
-	data->locked_fonts[0] = ptr_array_zeroed_new (1 + data->font->patterns->len);
-	data->locked_fonts[1] = ptr_array_zeroed_new (1 + data->font->patterns->len);
 
 	if (data->font->have_metrics) {
 		draw->width = data->font->width;
@@ -660,21 +665,18 @@
 		guint i;
 		gint n, width, height, min = G_MAXINT, max = G_MININT;
 		FcChar32 c;
-		GPtrArray *locked_fonts;
 
 		draw->width = 1;
 		draw->height = 1;
 		draw->ascent = 1;
 
-		locked_fonts = data->locked_fonts [data->cur_locked_fonts&1];
-
 		gdk_error_trap_push ();
 		n = width = height = 0;
 		/* Estimate a typical cell width by looking at single-width
 		 * characters. */
 		for (i = 0; i < sizeof (VTE_DRAW_SINGLE_WIDE_CHARACTERS) - 1; i++) {
 			c = VTE_DRAW_SINGLE_WIDE_CHARACTERS[i];
-			font = _vte_xft_font_for_char (data->font, c, locked_fonts);
+			font = _vte_xft_font_for_char (data->font, c);
 			if (font != NULL) {
 				memset (&extents, 0, sizeof (extents));
 				_vte_xft_text_extents (data->font, font, c, &extents);
@@ -705,7 +707,7 @@
 		prev_font = NULL;
 		for (i = 0; i < G_N_ELEMENTS (wide_chars); i++) {
 			c = wide_chars[i];
-			font = _vte_xft_font_for_char (data->font, c, locked_fonts);
+			font = _vte_xft_font_for_char (data->font, c);
 			if (font != NULL) {
 				if (n && prev_font != font) {/* font change */
 					width = howmany (width, n);
@@ -775,8 +777,7 @@
 
 	data = (struct _vte_xft_data*) draw->impl_data;
 	if (data->font != NULL) {
-		ftfont = _vte_xft_font_for_char (data->font, c,
-				data->locked_fonts[data->cur_locked_fonts&1]);
+		ftfont = _vte_xft_font_for_char (data->font, c);
 		if (ftfont != NULL) {
 			width = _vte_xft_char_width (data->font, ftfont, c, columns);
 			if (width != 0) {
@@ -805,19 +806,16 @@
 	gsize i, j;
 	gint width, y_off, x_off, char_width;
 	XftFont *font, *ft;
-	GPtrArray *locked_fonts;
 
 	data = (struct _vte_xft_data*) draw->impl_data;
 	if (G_UNLIKELY (data->font == NULL)){
 		return; /* cannot draw anything */
 	}
-	locked_fonts = data->locked_fonts[data->cur_locked_fonts&1];
 
 	/* find the first displayable character ... */
 	font = NULL;
 	for (i = 0; i < n_requests; i++) {
-		font = _vte_xft_font_for_char (data->font,
-				requests[i].c, locked_fonts);
+		font = _vte_xft_font_for_char (data->font, requests[i].c);
 		if (G_UNLIKELY (font == NULL)) {
 			continue;
 		}
@@ -867,7 +865,7 @@
 			ft = NULL;
 			while (++i < n_requests) {
 				ft = _vte_xft_font_for_char (data->font,
-						requests[i].c, locked_fonts);
+						requests[i].c);
 				if (G_UNLIKELY (ft == NULL)) {
 					continue;
 				}
@@ -914,8 +912,8 @@
 
 	data = (struct _vte_xft_data*) draw->impl_data;
 	if (data->font != NULL &&
-			_vte_xft_font_for_char (data->font, request->c,
-				data->locked_fonts[data->cur_locked_fonts&1]) != NULL) {
+			_vte_xft_font_for_char (data->font, request->c)
+				!= NULL) {
 		_vte_xft_draw_text (draw, request, 1, color, alpha);
 		return TRUE;
 	}
@@ -929,8 +927,7 @@
 
 	data = (struct _vte_xft_data*) draw->impl_data;
 	if (data->font != NULL &&
-			_vte_xft_font_for_char (data->font, c,
-				data->locked_fonts[data->cur_locked_fonts&1]) != NULL) {
+			_vte_xft_font_for_char (data->font, c) != NULL) {
 
 		return TRUE;
 	}
