GNOME Bugzilla – Bug 164357
PATCH_NEEDED: memory leak in pango_layout_get_extents()
Last modified: 2005-01-17 15:38:01 UTC
Please describe the problem: The following code will reproduce the leak. Defining DO_LEAK enables the leak: ----------------------------------------- #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; } ------------------------------- Steps to reproduce: 1. Call pango_layout_get_extents(). 2. Watch total memory usage. Actual results: Several megabytes of memory steadily accumulate without being freed, until killed by kernel. Expected results: Memory is initially allocated, and then remains constant for remaining runtime of code. Does this happen every time? Yes. Other information:
It's the fontmap that is leaking there... while it is a bug, there is no reason for a program to continually create fontmaps. fontmaps are expensive objects and should be kept around. The reason why it isn't leaking until you call get_extents() is simply that only with the get_extents() call does Pango need to load fonts. *** This bug has been marked as a duplicate of 143542 ***