freetype-devel
[Top][All Lists]
Advanced

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

Re: [ft-devel] memory leak


From: Werner LEMBERG
Subject: Re: [ft-devel] memory leak
Date: Tue, 05 Aug 2008 16:31:50 +0200 (CEST)

> fttimer calls FT_Done_Glyph() twice on each FT_Glyph object: a first
> time in ConvertRaster() just after FT_Glyph_To_Bitmap(), and a
> second time at the end of the while() loop with the comment "/* Now
> free all loaded outlines */"
>
> I did the same in my program and it worked, I don't have memory
> leaks reported anymore, so thank you for the hint :)
>
> Anyway, I don't understand why FT_Done_Glyph() has to be called
> twice on each FT_Glyph object.

The function FT_Glyph_To_Bitmap() is a bit tricky.  In fttimer.c, it
is use like this:

  FT_Glyph  glyphs[MAX_GLYPHS]

  ...

  for ( idx = 0; i < MAX_GLYPHS; i++ )
  {
    bitmap = glyphs[idx];

    ...

    FT_Glyph_To_Bitmap( &bitmap,
                        antialias ? FT_RENDER_MODE_NORMAL
                                  : FT_RENDER_MODE_MONO,
                        0,
                        0 );

    FT_Done_Glyph( bitmap );
  }

  ...

  for ( idx = 0; i < MAX_GLYPHS; i++ )
    FT_Done_Glyph( glyphs[idx] );

Two things:

  . The in-value of `bitmap' is not the same as the out-value `bitmap'
    (we have a pointer to a pointer)!  This means that after the call
    to FT_Glyph_To_Bitmap(), `bitmap' points to a different FT_Glyph
    object.

  . Note that the fourth parameter of FT_Glyph_To_Bitmap() is zero;
    this means that the in-value of `bitmap' is not destroyed.

The first call to FT_Done_Glyph destroys the `bitmap' object (which no
longer points into the `glyphs' array), the second call loops over the
elements of `glyphs'.


    Werner




reply via email to

[Prev in Thread] Current Thread [Next in Thread]