GNOME Bugzilla – Bug 753048
GtkImage leak when a GtkButton subclass calls gtk_button_set_image in its ::init() vfunc
Last modified: 2015-08-04 02:37:57 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
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.
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 ;)