Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - agordeevw

Pages: [1]
1
Quote
I'm not certain how FT works in that case, but it seems to me, that the glyph may get replaced with the "stroked" glyph. But by not destroying the origin/source glyph, SFML creates a memory leak, as the clean up code only destroys the "stroked" glyph and never destroys the source glyph.
Exactly this happens.

FT_Glyph_Stroke(...) definition is in the link in previous message.
All functions except FT_ALLOC(...) are defined in
http://git.savannah.gnu.org/cgit/freetype/freetype2.git/tree/src/base/ftglyph.c

FT_Glyph is defined as a pointer to a struct FT_GlyphRec, which is defined in
http://git.savannah.gnu.org/cgit/freetype/freetype2.git/tree/include/freetype/ftglyph.h.

Inside FT_Glyph_Stroke(...) a new pointer FT_Glyph is created and origin glyph is copied in the new FT_Glyph using FT_Glyph_Copy(...) function, which allocates memory to the new glyph, so the new FT_Glyph now points to memory containing the copy of origin.

FT_EXPORT_DEF( FT_Error )
  FT_Glyph_Stroke( FT_Glyph    *pglyph,
                   FT_Stroker   stroker,
                   FT_Bool      destroy )
  {
    [...]
    FT_Glyph  glyph = NULL;

    [...]

    glyph = *pglyph;
    [...]
    {
      FT_Glyph  copy;

      error = FT_Glyph_Copy( glyph, &copy );   // Memory to origin glyph copy is allocated here
      if ( error )
        goto Exit;

      glyph = copy;
    }
    [...]
 

FT_Glyph_Copy(...) calls ft_new_glyph(...), which in turn calls FT_ALLOC(...), which allocates memory for the copy.

After manipulations with copy (outline and other things related to modification of the glyph) pointer *pglyph is redirected to the new FT_Glyph, and if origin glyph isn't destroyed by specifying destroy argument as "true" (which would call FT_Done_Glyph(...) on origin), memory for origin glyph is left hanging, which supposedly produces the leak, because origin glyph isn't used anywhere in subsequent code in Font.cpp.

   
[...]
if ( destroy )
      FT_Done_Glyph( *pglyph );   // Memory for origin glyph is cleared

    *pglyph = glyph;    // If destroy is "false", origin glyph wouldn't be destroyed and will be left hanging
                        // for someone else to use/clear
    goto Exit;

[...]
} // the function end
 

So it seems to me that setting destroy argument to "true" is a fix.

Pages: [1]
anything