[Fontconfig] FontConfig memory question

mathog mathog at caltech.edu
Wed Feb 12 23:39:51 CET 2014


He all,

The question concerns the bit of FontConfig using code below (sorry 
about the wrap) which is leaking memory in some mysterious manner, but 
so far only when compiled into Inkscape, and only, apparently, for 
certain fonts.  (The one case where I see this is a test sample 
containing Hebrew Ezra SIL and Ezra SIL SR fonts.)  The code is part of 
the file text_reassemble.c which is from libTERE (on sourceforge) but it 
is also included in Inkscape.  I have traced through this and in every 
instance "pattern", the pointer to the leaking memory, was sent to 
FcPatternDestroy.  Yet when run in valgrind the line where that pointer 
is attached to memory shows up as a leak.

Any idea what this might be???  I thought that it might have been a case 
where something later on replaces a field in "pattern", but that should 
have given the "definitely lost" message in valgrind, not "still 
reachable".  The only other thing that comes to mind is that FcNameParse 
itself leaks memory internally for certain fontspec's, and this has 
nothing to do with the "pattern" variable in this code.  This is on a 
Ubuntu 12.04.04 system, with fontconfig 2.8.0-3ubuntu9.1 packages.

Here is the code snippet:

    pattern = FcNameParse((const FcChar8 *)fontspec);  //<--- line 750, 
problem is here
    while(1) {  /* this is NOT a loop, it uses breaks to avoid gotos and 
deep nesting */
    if(!(pattern)){                                                       
                           status = -2;   break; }
       if(!FcConfigSubstitute(NULL, pattern, FcMatchPattern)){            
                              status = -3;   break; };
       FcDefaultSubstitute(pattern);
       /*  get a fontset, trimmed to only those with new glyphs as 
needed, so that missing glyph's may be handled */
       if(!(fontset = FcFontSort (NULL,pattern, FcTrue, NULL, &result)) 
|| (result != FcResultMatch)){ status = -4;   break; }
       if(!(fpat = FcFontRenderPrepare(NULL, pattern, 
fontset->fonts[0]))){                            status = -405; break; }
       if(FcPatternGetString(  fpat, FC_FILE,   0, (FcChar8 **)&filename) 
  != FcResultMatch){          status = -5;   break; }
       if(FcPatternGetDouble(  fpat, FC_SIZE,   0,  &fd)                  
  != FcResultMatch){          status = -6;   break; }

       /* copy these into memory for external use */
       fsp                   = &(fti->fonts[fti->used]);
       fsp->fontset          = fontset;
       fsp->alts             = NULL;  /* Initially no links to alternate 
fonts */
       fsp->space            = 0;
       fsp->file             = (uint8_t *) U_strdup((char *) filename);
       fsp->fontspec            = (uint8_t *) U_strdup((char *) 
fontspec);
       fsp->fpat             = fpat;
       fsp->fsize            = fd;
       break;
    }
    /* release FC's own memory related to this call that does not need to 
be kept around so that face will work */
    if(pattern)FcPatternDestroy(pattern); /* done with this memory */

and here is the valgrind log:

45 bytes in 2 blocks are still reachable in loss record 26,064 of 38,661
    at 0x402BE68: malloc (in 
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
    by 0x4FAFD42: ??? (in /usr/lib/i386-linux-gnu/libfontconfig.so.1.4.4)
    by 0x4FB0914: ??? (in /usr/lib/i386-linux-gnu/libfontconfig.so.1.4.4)
    by 0x4FADF4B: FcNameParse (in 
/usr/lib/i386-linux-gnu/libfontconfig.so.1.4.4)
    by 0x83868EF: ftinfo_load_fontname (text_reassemble.c:750)
    by 0x83A4F57: 
Inkscape::Extension::Internal::Emf::myEnhMetaFileProc(char*, unsigned 
int, Inkscape::Extension::Internal::EMF_CALLBACK_DATA*) 
(emf-inout.cpp:3047)
    by 0x83A782D: 
Inkscape::Extension::Internal::Emf::open(Inkscape::Extension::Input*, 
char const*) (emf-inout.cpp:3429)
    by 0x8322F09: Inkscape::Extension::Input::open(char const*) 
(input.cpp:153)
    by 0x8320A99: 
Inkscape::Extension::open(Inkscape::Extension::Extension*, char const*) 
(system.cpp:117)
    by 0x80F58FC: sp_file_open(Glib::ustring const&, 
Inkscape::Extension::Extension*, bool, bool) (file.cpp:274)
    by 0x8087762: sp_main_gui(int, char const**) (main.cpp:1065)

Thank you,

David Mathog
mathog at caltech.edu
Manager, Sequence Analysis Facility, Biology Division, Caltech



More information about the Fontconfig mailing list