Re: memory leak with gdk_fontset_load/gdk_font_unref while using XFree-4 libs



Try the attached patch.
That seems to kill mem leaks but I think fontset loading routines in
XFree86-4 are quite broken. Just monitor XLoadQueryFont functions.
You will know.


On Fri, Oct 06, 2000 at 01:06:12PM +0200, Guillaume Cottenceau wrote:
> Hi,
> 
> I am developper for MandrakeSoft, who produces the Linux distribution
> called Linux-Mandrake.
> 
> I had trouble with xmms, actually a memory leak that made it eat more than
> 150 Megabytes of memory after a long use.
> 
> After much investigation, I finally figured out where the problem comes
> from, and the little program at the bottom can reproduce it:
> gdk_font_unref seems to not release correctly the memory if it was created
> with gdk_fontset_load; additionnally, it seems that the problem only
> occurs when the prog is linked against X libraries from XFree-4 (does NOT
> appear when the prog is linked against XFree-3).
> 
> I did not verify on current CVS if this bug seems to be fixed; however I
> checked the archive of this ML and it seems that it was not reported
> before.
> 
> 
> -=-=-=-=-=-=-=-
> 
> #include <stdio.h>
> #include <gtk/gtk.h>
> 
> void print_mem()
> {
>    FILE *stream_;
>    char point[1000];
>    char filen[100];
>    char *f_,*g_;
>    int t;
> 
>    t = getpid();
>    sprintf(filen, "/proc/%d/status", t);
> 
>    if((stream_ = fopen(filen, "r")) == NULL)
>      return;
> 
>    fread(point, 1, 1000, stream_);
>    fclose(stream_);
> 
>    point[999] = '\0';
>    f_ = (char *) strstr(point,"VmSize");
>    if (!f_) return;
>    g_ = (char *) strchr(f_, '\n');
>    if (!g_) return;
>    g_[1] = '\0';
>    printf(f_);
> }
> 
> int main(int argc, char **argv)
> {
>   GdkFont *font = NULL;
>   int i;
> 
>   gtk_init(&argc, &argv);
> 
>   printf("Starting at:\t\t\t"); print_mem();
> 
>   for (i=0; i<200; i++)
>     {
>       font = gdk_font_load("-adobe-helvetica-bold-r-*-*-10-*");
>       gdk_font_unref(font);
>     }
> 
>   printf("After some font_load:\t\t"); print_mem();
> 
>   for (i=0; i<200; i++)
>     {
>       font = gdk_fontset_load("-adobe-helvetica-bold-r-*-*-10-*,*-r-*");
>       gdk_font_unref(font);
>     }
> 
>   printf("After some fontset_load:\t"); print_mem();
> }
> 
> 
> -=-=-=-=-=-=-=-
> 
> Output of this program on a Linux-Mandrake 7.2-beta machine is:
> 
> Starting at:                    VmSize:     4252 kB
> After some font_load:           VmSize:     4252 kB
> After some fontset_load:        VmSize:     4844 kB
> 
> 
> Versions of progs we use:
> 
> gtk+-1.2.8
> glib-1.2.8
> XFree86-4.0.1
> glibc-2.1.3
> linux-2.2.17
> 
> 
> -- 
> Guillaume Cottenceau -- Distribution Developer for MandrakeSoft
> http://www.mandrakesoft.com/~gc/
>  
> 
> _______________________________________________
> gtk-devel-list mailing list
> gtk-devel-list gnome org
> http://mail.gnome.org/mailman/listinfo/gtk-devel-list
--- omGeneric.c.orig	Mon Oct  9 22:36:45 2000
+++ omGeneric.c	Mon Oct  9 22:38:07 2000
@@ -740,6 +740,8 @@
     int		length = 0;
     int		num_fields;
 
+    if (font_data->xlfd_name) Xfree(font_data->xlfd_name);
+
    /* If the font specified by "pattern" is expandable to be
     * a member of "font_data"'s FontSet, we've found a match.
     */
@@ -1460,6 +1462,7 @@
 	font_set = gen->font_set;
 	font_set_num = gen->font_set_num;
 	for( ; font_set_num-- ; font_set++) {
+	    if(font_set->font) XFreeFont(dpy, font_set->font); 
 	    if(font_set->font_data) {
 		free_fontdataOC(dpy,
 			font_set->font_data, font_set->font_data_count);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]