GNOME Bugzilla – Bug 528227
memory leak with combination of pango_ft2_font_map_new and pango_layout_get_extents
Last modified: 2008-04-15 18:14:55 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
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 ***