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 616894 - Pango attribute objects leak memory
Pango attribute objects leak memory
Status: RESOLVED FIXED
Product: gnome-perl
Classification: Bindings
Component: Pango
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtk2-perl-bugs
gtk2-perl-bugs
Depends on:
Blocks:
 
 
Reported: 2010-04-26 21:57 UTC by Quentin Sculo
Modified: 2010-05-16 11:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Glib::Boxed::DESTROY: handle unregistered children (1.17 KB, patch)
2010-04-26 22:57 UTC, Torsten Schoenfeld
none Details | Review
Don't leak Pango::Attribute objects (8.99 KB, patch)
2010-04-27 22:24 UTC, Torsten Schoenfeld
committed Details | Review

Description Quentin Sculo 2010-04-26 21:57:12 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.
Comment 1 Torsten Schoenfeld 2010-04-26 22:57:34 UTC
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?
Comment 2 Torsten Schoenfeld 2010-04-26 22:57:47 UTC
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.
Comment 3 Torsten Schoenfeld 2010-04-27 22:24:55 UTC
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.
Comment 4 Torsten Schoenfeld 2010-04-27 22:27:22 UTC
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.
Comment 5 Torsten Schoenfeld 2010-05-16 11:51:34 UTC
I committed the second patch now.

Attachment 159729 [details] pushed as f59a97e - Don't leak Pango::Attribute objects