Skip to content

Fix memory management of vala generated plugins

Arthur D. requested to merge spinal84/xfce4-panel:transfer-fix into master

The wrong use of "(transfer full)" statements results in vala generated code that does g_object_unref() on widgets that were already destroyed by containers they were hold by.

An example error message: (wrapper-2.0:123214): GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT (object)' failed

The error was produced by xfce4-notes plugin while removing from the panel.

If we look in libxfce4panel/xfce-panel-convenience.c we can find that xfce_panel_create_button() and xfce_panel_create_toggle_button() return objects created by gtk_button_new() and gtk_toggle_button_new().

Both GtkButton and GtkToggleButton are ancestors of GInitiallyUnowned: https://docs.gtk.org/gtk3/class.ToggleButton.html https://docs.gtk.org/gtk3/class.Button.html

This means that they are created with floating references. The floating references are converted to ordinary by g_object_ref_sink() when widget (button in our example) is added to a container.

But in our case vala generates code that assumes that the buttons are hold with ordinary references. And this leads to possible segfaults if vala generated code will do g_object_unref() on the widgets that were already destroyed with containers they were hold by.

Following docs can be used for better understanding.

https://docs.gtk.org/gobject/method.Object.ref_sink.html https://discourse.gnome.org/t/about-transfer-in-gobject-introspection/2500 https://gi.readthedocs.io/en/latest/annotations/giannotations.html

Merge request reports

Loading