[cairo-commit] src/cairo-type1-subset.c

罗晶华 Jinghua Luo jinghua at kemper.freedesktop.org
Tue Feb 13 19:54:19 PST 2007


 src/cairo-type1-subset.c |   34 +++++++++++++++++++++++-----------
 1 files changed, 23 insertions(+), 11 deletions(-)

New commits:
diff-tree 17b4496ae9df539c48c830b21c4477e763ba4e5d (from 01a133167c48e7985515ae29f4a87de7952d1373)
Author: Jinghua Luo <sunmoon1997 at gmail.com>
Date:   Wed Feb 14 11:52:11 2007 +0800

    type1-subset: fix error handling.
    
    This fixes potenial memory leak and leaving font face locked on error.

diff --git a/src/cairo-type1-subset.c b/src/cairo-type1-subset.c
index 4455ca5..73b0b90 100644
--- a/src/cairo-type1-subset.c
+++ b/src/cairo-type1-subset.c
@@ -107,6 +107,7 @@ _cairo_type1_font_subset_create (cairo_u
                                  cairo_bool_t                hex_encode)
 {
     cairo_ft_unscaled_font_t *ft_unscaled_font;
+    cairo_status_t status;
     FT_Face face;
     PS_FontInfoRec font_info;
     cairo_type1_font_subset_t *font;
@@ -116,12 +117,16 @@ _cairo_type1_font_subset_create (cairo_u
 
     face = _cairo_ft_unscaled_font_lock_face (ft_unscaled_font);
 
-    if (FT_Get_PS_Font_Info(face, &font_info) != 0)
-	return CAIRO_INT_STATUS_UNSUPPORTED;
+    if (FT_Get_PS_Font_Info(face, &font_info) != 0) {
+	status = CAIRO_INT_STATUS_UNSUPPORTED;
+        goto fail1;
+    }
 
     font = calloc (sizeof (cairo_type1_font_subset_t), 1);
-    if (font == NULL)
-	return CAIRO_STATUS_NO_MEMORY;
+    if (font == NULL) {
+	status = CAIRO_STATUS_NO_MEMORY;
+        goto fail1;
+    }
 
     font->base.unscaled_font = _cairo_unscaled_font_reference (unscaled_font);
     font->base.num_glyphs = face->num_glyphs;
@@ -132,8 +137,10 @@ _cairo_type1_font_subset_create (cairo_u
     font->base.ascent = face->ascender;
     font->base.descent = face->descender;
     font->base.base_font = strdup (face->family_name);
-    if (font->base.base_font == NULL)
-	goto fail1;
+    if (font->base.base_font == NULL) {
+        status = CAIRO_STATUS_NO_MEMORY;
+	goto fail2;
+    }
 
     for (i = 0, j = 0; font->base.base_font[j]; j++) {
 	if (font->base.base_font[j] == ' ')
@@ -143,8 +150,10 @@ _cairo_type1_font_subset_create (cairo_u
     font->base.base_font[i] = '\0';
 
     font->glyphs = calloc (face->num_glyphs, sizeof font->glyphs[0]);
-    if (font->glyphs == NULL)
-	goto fail2;
+    if (font->glyphs == NULL) {
+        status = CAIRO_STATUS_NO_MEMORY;
+	goto fail3;
+    }
 
     font->hex_encode = hex_encode;
     font->num_glyphs = 0;
@@ -159,12 +168,15 @@ _cairo_type1_font_subset_create (cairo_u
 
     return CAIRO_STATUS_SUCCESS;
 
- fail2:
+ fail3:
     free (font->base.base_font);
- fail1:
+ fail2:
+    _cairo_unscaled_font_destroy (unscaled_font);
     free (font);
+ fail1:
+    _cairo_ft_unscaled_font_unlock_face (ft_unscaled_font);
 
-    return CAIRO_STATUS_NO_MEMORY;
+    return status;
 }
 
 static int


More information about the cairo-commit mailing list