fltk-1.3.x-r8276 / Linux 2.6.33.3 (tinycore) on i686 / gcc 4.4.3

find_best_font() keeps a static pointer to the list of font names provided by 
libx11. find_best_font() frees and then re-queries that list from libx11 every 
time find_best_font() is run. At program termination, that list cannot be freed.

I don't have an elegant solution, but I suggest an improvement that auto-frees. 
Rather than keeping a static pointer, I find_best_font() keeps a static, fixed 
length array.

Patch:

125c125,126
<   static char **list = NULL;
---
>   char **list = NULL;
>   static char retval[128]; //for storing/returning our font name string
127c128
<   if (list) XFreeFontNames(list);
---
> // if (list) XFreeFontNames(list);
129c130,133
<   if (!list) return "fixed";
---
>   if (!list) {
>     strcpy(retval, "fixed");
>     return "fixed";
>     }
190c194,196
<   return name;
---
>   strcpy(retval, name);
>   XFreeFontNames(list);
>   return (const char *)&retval[0];



With that (and a couple other recent patches), Valgrind tells me my simple 
helloworld program runs without any leaks.

DLT
_______________________________________________
fltk mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to