GNOME Bugzilla – Bug 616894
Pango attribute objects leak memory
Last modified: 2010-05-16 11:51:41 UTC
I've only tested Pango::AttrSize and Pango::AttrWeight, but I guess it's the same for all of them. Running this : perl -e 'use Pango; Pango::AttrSize->new(10) while 1' will make memory usage grow continuously.
This is due to the way the various attribute wrappers are set up. Pango::Attribute is a real boxed wrapper for a real boxed type. The others, like Pango::AttrSize, are then set up by hand to inherit from Pango::Attribute and thus from Glib::Boxed. If one of these attributes now goes out of scope, Glib::Boxed::DESTROY is called. But since Pango::AttrSize is not registered with the boxed type wrapper machinery, no C-level destroy function is called. I attach a patch for Glib which makes this issue go away, but I think this approach is very incorrect under certain circumstances. See the patch for details. muppet, what do you think?
Created attachment 159650 [details] [review] Glib::Boxed::DESTROY: handle unregistered children If a class is set to inherit from Glib::Boxed but is not actually registered as a boxed type (and so has no BoxedInfo associated with it), simply use the default destroy function. This way, at least the BoxedWrapper struct gets freed. FIXME: But what about a boxed wrapper that doesn't use default_boxed_wrap? If another package is set to inherit from that boxed wrapper, Glib::Boxed::DESTROY would still call default_boxed_destroy, which would most likely result in a segfault.
Created attachment 159729 [details] [review] Don't leak Pango::Attribute objects packages as aliases for real types. Use this to register all Pango::Attribute subclasses, say Pango::AttrSize, as aliases for Pango::Attribute (i.e., PANGO_TYPE_ATTRIBUTE). This way, when Glib::Boxed::DESTROY tries to look up "Pango::AttrSize", it finds the information registered for "Pango::Attribute", including the correct memory-freeing function.
Sorry, git-bz ate the first line of my comment there. It should have read: I think I found a better fix. Glib provides the means to register packages as aliases for real types. Use this to register all Pango::Attribute subclasses, say Pango::AttrSize, as aliases for Pango::Attribute (i.e., PANGO_TYPE_ATTRIBUTE). This way, when Glib::Boxed::DESTROY tries to look up "Pango::AttrSize", it finds the information registered for "Pango::Attribute", including the correct memory-freeing function.
I committed the second patch now. Attachment 159729 [details] pushed as f59a97e - Don't leak Pango::Attribute objects