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

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


This somewhat ugly fix takes into account that font_set->font_name
before load_font_info() are individually allocated buffers wheras after
load_font_info() they are pointers into the oc->core.font_info.font_name_list
buffer.

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

diff --git a/modules/om/generic/omGeneric.c b/modules/om/generic/omGeneric.c
index 453cc61..de3fb03 100644
--- a/modules/om/generic/omGeneric.c
+++ b/modules/om/generic/omGeneric.c
@@ -1430,7 +1430,8 @@ free_fontdataOC(
 
 static void destroy_fontdata(
     XOCGenericPart *gen,
-    Display *dpy)
+    Display *dpy,
+    int free_font_names)
 {
     FontSet	font_set = (FontSet) NULL;
     int		font_set_num = 0;
@@ -1454,6 +1455,10 @@ static void destroy_fontdata(
 		Xfree(font_set->font_data);
 		font_set->font_data = NULL;
 	    }
+	    if(free_font_names && font_set->font_name) {
+		Xfree(font_set->font_name);
+		font_set->font_name = NULL;
+	    }
 	    if(font_set->substitute) {
 		free_fontdataOC(dpy,
 			font_set->substitute, font_set->substitute_num);
@@ -1497,7 +1502,7 @@ destroy_oc(
 	_XlcCloseConverter(gen->utf8_to_cs);
 
 /* For VW/UDC start */ /* Change 1996.01.8 */
-    destroy_fontdata(gen,dpy);
+    destroy_fontdata(gen, dpy, oc->core.font_info.font_name_list == NULL);
 /*
 */
 /* For VW/UDC end */
-- 
1.6.5.2



More information about the xorg-devel mailing list