After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 528227 - memory leak with combination of pango_ft2_font_map_new and pango_layout_get_extents
memory leak with combination of pango_ft2_font_map_new and pango_layout_get_e...
Status: RESOLVED DUPLICATE of bug 143542
Product: pango
Classification: Platform
Component: general
1.20.x
Other All
: Normal critical
: ---
Assigned To: pango-maint
pango-maint
Depends on:
Blocks:
 
 
Reported: 2008-04-15 14:43 UTC by Jeff Mast
Modified: 2008-04-15 18:14 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Jeff Mast 2008-04-15 14:43:26 UTC
Please describe the problem:
When pango_ft2_font_map_new and pango_layout_get_extents are used together, it results in a memory leak.

Steps to reproduce:
The following code snippet causes huge memory leaks if DO_LEAK is defined.
However, note that if DO_LEAK is defined and pango_ft2_font_map_new (and associated g_object_unref(fontmap))
are moved outside of the while loop, then the leak does not happen.

---------

#include <stdlib.h>
#include <stdio.h>
#include <pango/pango.h>
#include <pango/pangoft2.h>

int main(int argc, char *argv[])
{
  PangoContext *context;
  PangoFontMap *fontmap=NULL;
  PangoLayout *layout;
  int dpi = 96;

  g_type_init();

  if (g_file_test("./pangorc", G_FILE_TEST_EXISTS))
    putenv("PANGO_RC_FILE=./pangorc");

  while (1)
{
  
    /* create a font map */
    fontmap = pango_ft2_font_map_new();

pango_ft2_font_map_set_resolution(PANGO_FT2_FONT_MAP(fontmap),dpi,dpi);
  
    /* create a context */
    context =
pango_ft2_font_map_create_context(PANGO_FT2_FONT_MAP(fontmap));

    /* free the fontmap */
    g_object_unref(fontmap);
  
    /* make a layout */
    layout = pango_layout_new(context);
#ifdef DO_LEAK
    PangoRectangle logical_rect;
    pango_layout_get_extents(layout, NULL, &logical_rect);
#endif
  
    /* free the layout */
    g_object_unref(layout);

    /* free the context */
    g_object_unref(context);
}
  
  return EXIT_SUCCESS;
}


Actual results:
huge memory leak

Expected results:


Does this happen every time?
yes

Other information:
This was submitted to bugs.debian.org, closed, but never fixed: see:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=290538
Comment 1 Behdad Esfahbod 2008-04-15 18:14:55 UTC
Thanks for the bug report. This particular bug has already been reported into our bug tracking system, but please feel free to report any further bugs you find.

In short, don't do that.  Create and reuse one fontmap.

*** This bug has been marked as a duplicate of 143542 ***