[PATCH 1/2] libX11: Fix potential memory leaks during font set loading.

Kim Woelders kim at woelders.dk
Sat Nov 21 08:10:39 PST 2009


These may be triggered by errors during XLFD name parsing in get_rotate_fontname().

Signed-off-by: Kim Woelders <kim at woelders.dk>
---
 modules/om/generic/omGeneric.c |   16 +++++++---------
 1 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/modules/om/generic/omGeneric.c b/modules/om/generic/omGeneric.c
index 4fdc11b..453cc61 100644
--- a/modules/om/generic/omGeneric.c
+++ b/modules/om/generic/omGeneric.c
@@ -541,7 +541,7 @@ static char *
 get_rotate_fontname(
     char *font_name)
 {
-    char *pattern = NULL, *ptr = NULL;
+    char *pattern, *ptr;
     char *fields[CHARSET_ENCODING_FIELD];
     char str_pixel[32], str_point[4];
     char *rotate_font_ptr = NULL;
@@ -577,7 +577,7 @@ get_rotate_fontname(
     }
 
     if(field_num < CHARSET_ENCODING_FIELD)
-	return NULL;
+	goto quit;
 
     /* Pixel Size field : fields[6] */
     for(ptr = fields[PIXEL_SIZE_FIELD - 1] ; ptr && *ptr; ptr++) {
@@ -586,9 +586,7 @@ get_rotate_fontname(
 	        strcpy(pattern, font_name);
 		return(pattern);
 	    }
-	    if(pattern)
-		Xfree(pattern);
-	    return NULL;
+	    goto quit;
 	}
     }
     pixel_size = atoi(fields[PIXEL_SIZE_FIELD - 1]);
@@ -607,11 +605,11 @@ get_rotate_fontname(
 
     /* Max XLFD length is 255 */
     if (len > XLFD_MAX_LEN)
-	return NULL;
+	goto quit;
 
     rotate_font_ptr = (char *)Xmalloc(len + 1);
     if(!rotate_font_ptr)
-	return NULL;
+	goto quit;
 
     rotate_font_ptr[0] = '\0';
 
@@ -621,8 +619,8 @@ get_rotate_fontname(
 	strcat(rotate_font_ptr, fields[field_num]);
     }
 
-    if(pattern)
-	Xfree(pattern);
+  quit:
+    Xfree(pattern);
 
     return rotate_font_ptr;
 }
-- 
1.6.5.2



More information about the xorg-devel mailing list