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 753048 - GtkImage leak when a GtkButton subclass calls gtk_button_set_image in its ::init() vfunc
GtkImage leak when a GtkButton subclass calls gtk_button_set_image in its ::i...
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkButton
3.17.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2015-07-30 09:19 UTC by Christophe Fergeau
Modified: 2015-08-04 02:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test case exhibiting the leak (2.67 KB, text/plain)
2015-07-30 09:19 UTC, Christophe Fergeau
Details

Description Christophe Fergeau 2015-07-30 09:19:12 UTC
Created attachment 308439 [details]
Test case exhibiting the leak

gtk_button_set_image() should be taking ownership of the passed in GtkImage, and free it when needed. However, if it's called before GtkButton::constructed has run, this is not going to work:

gtk_button_set_image() relies on gtk_button_construct_child() to take ownership of the passed in GtkImage, but gtk_button_construct_child() has an early return when it's not constructed yet:

  if (!priv->constructed)
    return;

See attached test case
Comment 1 Matthias Clasen 2015-07-31 01:20:01 UTC
I'm tempted to declare this notabug. init() is not the right place to call arbitary functions on your superclass - just initialize your own fields and be done.
Comment 2 Christophe Fergeau 2015-07-31 07:41:51 UTC
Maybe we could at least have some runtime warnings when doing that in this case as this is potentially harmful? I'd argue that this should also be stated in some documentation ("Don't call arbitrary functions on your superclass from ::init()"), not sure where though ;)