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 658200 - gtk_toolbar_finalize() does stuff it shouldn't
gtk_toolbar_finalize() does stuff it shouldn't
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2011-09-04 21:13 UTC by Owen Taylor
Modified: 2011-09-05 15:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test case for reproducing bug (703 bytes, text/plain)
2011-09-04 21:14 UTC, Owen Taylor
  Details
GtkToolbar: Move child removal to dispose (4.24 KB, patch)
2011-09-05 15:09 UTC, Matthias Clasen
committed Details | Review

Description Owen Taylor 2011-09-04 21:13:11 UTC
gtk_toolbar_finalize() has code to remove and destroy all its internal and external children. The external children don't matter since gtk_container_destroy() has already removed them, but the internal child removals:

  if (priv->arrow_button)
    gtk_widget_unparent (priv->arrow_button);

and:

  if (priv->menu)
    {
      g_signal_handlers_disconnect_by_func (priv->menu,
                                            menu_deactivated, toolbar);
      gtk_widget_destroy (GTK_WIDGET (priv->menu));
    }

cause problems because finalize because they will cause ::parent-set to be emitted on the children, with the toolbar as an old_parent argument. And once you are in finalize with a refcount of zero, you can't use an object as a signal parameter.

*Mostly* this ends up not mattering since we short-circuit the ::parent-set if there are no signal handlers on the child, but if you have an overridden class closure or emission hook, you get a warning:

GLib-GObject-CRITICAL **: g_object_ref: assertion `object->ref_count > 0' failed

Will attach a program that demonstrates. The fix is to move the widget manipulation that's in gtk_toolbar_finalize() to a gtk_toolbar_dispose() (will need a little added safety against being run multiple times, such as nulling out priv->arrow-button.)
Comment 1 Owen Taylor 2011-09-04 21:14:23 UTC
Created attachment 195640 [details]
Test case for reproducing bug
Comment 2 Owen Taylor 2011-09-04 21:14:45 UTC
(Should note that this was originally from bug 642527)
Comment 3 Matthias Clasen 2011-09-05 15:09:41 UTC
The following fix has been pushed:
5445b3d GtkToolbar: Move child removal to dispose
Comment 4 Matthias Clasen 2011-09-05 15:09:43 UTC
Created attachment 195707 [details] [review]
GtkToolbar: Move child removal to dispose

Doing it in finalize is too late and can cause various problems
in ::parent-set signal handlers.