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 164357 - PATCH_NEEDED: memory leak in pango_layout_get_extents()
PATCH_NEEDED: memory leak in pango_layout_get_extents()
Status: RESOLVED DUPLICATE of bug 143542
Product: pango
Classification: Platform
Component: general
1.8.x
Other All
: Normal critical
: ---
Assigned To: pango-maint
pango-maint
Depends on:
Blocks:
 
 
Reported: 2005-01-17 14:55 UTC by Sam Bromley
Modified: 2005-01-17 15:38 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Sam Bromley 2005-01-17 14:55:15 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:
Comment 1 Owen Taylor 2005-01-17 15:38:01 UTC
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 ***