nanogui: Truetype memory leak fixed ...


Previous by date: 22 Mar 2000 04:59:58 -0000 Re: OT TROLL: Re: What is the status of porting Opera to MicroWindows?, The Joker
Next by date: 22 Mar 2000 04:59:58 -0000 Re: OT TROLL: Re: What is the status of porting Opera to MicroWindows ?, Lalo Martins
Previous in thread:
Next in thread:

Subject: Truetype memory leak fixed ...
From: Martin Jolicoeur ####@####.####
Date: 22 Mar 2000 04:59:58 -0000
Message-Id: <38D850EA.37954D8@visuaide.com>

Hi Greg,

You made a fantastic job on the integration of the font libs !
There's maybe one or 2 things I would like to change .... But I'll come
back to you with that ....

For now, I can tell you I found the memory leak bug ... that was a
though one ....

You forgot to call GdUnloadFont in the nanox code ... it must have been
late when you code that one :-)

Plus, I changed a little bit the devfont.c and added freetype_init ...

Here are the patches to devfont.c and srvfunc.c ....

Enjoy

Martin Jolicoeur
GVT Project
####@####.####


--- ./microwin/src/nanox/srvfunc.c	Sun Mar 19 17:24:29 2000
+++ ./microwin_ok/src/nanox/srvfunc.c	Tue Mar 21 23:15:46 2000
@@ -622,6 +622,7 @@
 
 	if (listfontp == fontp) {
 		listfontp = fontp->next;
+		GdUnloadFont(fontp->pfont);
 		free(fontp);
 		return;
 	}
@@ -631,6 +632,7 @@
 		prevfontp = prevfontp->next;
 
 	prevfontp->next = fontp->next;
+	GdUnloadFont(fontp->pfont);
 	free(fontp);
 }
 

--- ./microwin/src/engine/devfont.c	Mon Mar 20 01:52:42 2000
+++ ./microwin_ok/src/engine/devfont.c	Tue Mar 21 23:35:46 2000
@@ -62,10 +62,11 @@
 #include <freetype/ftxkern.h>
 #include <math.h>
 
+TT_Engine 	engine;		/* THE ONLY freetype engine */
+
 typedef struct {
 	PMWFONTPROCS	procs;		/* common hdr*/
 	int		defencoding;
-	TT_Engine 	engine;		/* freetype stuff*/
 	TT_Face 	face;
 	TT_Instance	instance;
 	TT_CharMap 	char_map;
@@ -77,6 +78,7 @@
 	short 		last_pen_pos;
 } MWFREETYPEFONT, *PMWFREETYPEFONT;
 
+static int  freetype_init(PSD psd);
 static PMWFREETYPEFONT freetype_createfont(const char *name);
 static BOOL freetype_getfontinfo(PMWFONT pfont, PFONTINFO pfontinfo);
 static void freetype_gettextsize(PMWFONT pfont, const void *text,
@@ -94,6 +96,7 @@
 	freetype_unloadfont,
 	freetype_drawtext
 };
+
 #endif
 
 static PMWFONT	gr_pfont;            	/* current font*/
@@ -168,11 +171,14 @@
 	}
 
 #if HAVE_FREETYPE_SUPPORT
-	pfont = (PMWFONT)freetype_createfont(name);
-	if(pfont) {
-		gr_fontsize = height;
-		return pfont;
-	} else printf("freetype_createfont: %s not found\n", name);
+        /* Make sure the library is initialized */
+	if (freetype_init(psd)) {
+		pfont = (PMWFONT)freetype_createfont(name);
+		if(pfont) {
+			gr_fontsize = height;
+			return pfont;
+		} else printf("freetype_createfont: %s not found\n", name);
+	}
 #endif
 
 #if HAVE_T1LIB_SUPPORT
@@ -694,6 +700,27 @@
 #if HAVE_FREETYPE_SUPPORT
 static PIXELVAL gray_palette[5];
 
+static int
+freetype_init(PSD psd)
+{
+	static int inited = 0;
+
+	if (inited)
+		return 1;
+	
+	/* Init freetype library */
+	if (TT_Init_FreeType (&engine) != TT_Err_Ok) {
+		return 0;
+	}
+
+	/* Init kerning extension */
+	if (TT_Init_Kerning_Extension (engine) != TT_Err_Ok)
+		return 0;
+
+	inited = 1;
+	return 1;
+}
+
 static PMWFREETYPEFONT
 freetype_createfont(const char *name)
 {
@@ -708,18 +735,8 @@
 		return NULL;
 	pf->procs = &freetype_procs;
 
-	/* Init freetype library */
-	if (TT_Init_FreeType (&pf->engine) != TT_Err_Ok) {
-		free(pf);
-		return NULL;
-	}
-
-	/* Init kerning extension */
-	if (TT_Init_Kerning_Extension (pf->engine) != TT_Err_Ok)
-		goto out;
-
 	/* Load face */
-	if (TT_Open_Face (pf->engine, name, &pf->face) != TT_Err_Ok)
+	if (TT_Open_Face (engine, name, &pf->face) != TT_Err_Ok)
 		goto out;
 
 	/* Load first kerning table */
@@ -775,7 +792,6 @@
 	return pf;
 
 out:
-	TT_Done_FreeType (pf->engine);
 	free(pf);
 	return NULL;
 }
@@ -958,7 +974,7 @@
 
 	/* Set the "graylevels" */
 	if (gr_antialias)
-		TT_Set_Raster_Gray_Palette (pf->engine, virtual_palette);
+		TT_Set_Raster_Gray_Palette (engine, virtual_palette);
 
 	if(gr_antialias)
 		alphablend(psd, gray_palette, gr_foreground, gr_background,
@@ -1068,7 +1084,7 @@
 {
 	PMWFREETYPEFONT	pf = (PMWFREETYPEFONT)pfont;
 
-	TT_Done_FreeType(pf->engine);
+	TT_Close_Face( pf->face );	
 	free(pf);
 }
 #endif /* HAVE_FREETYPE_SUPPORT*/

Previous by date: 22 Mar 2000 04:59:58 -0000 Re: OT TROLL: Re: What is the status of porting Opera to MicroWindows?, The Joker
Next by date: 22 Mar 2000 04:59:58 -0000 Re: OT TROLL: Re: What is the status of porting Opera to MicroWindows ?, Lalo Martins
Previous in thread:
Next in thread:


Powered by ezmlm-browse 0.20.