GNOME Bugzilla – Bug 728452
gtk_tree_view_column_create_button creates button which is leaked
Last modified: 2017-10-06 23:49:14 UTC
The button created in gtk_tree_view_column_create_button is never destroyed (in the gtk_widget_destroy sense) and never diposed of. I added g_printerr ("Create button %p for column %p\n", priv->button, tree_column); g_signal_connect (priv->button, "destroy", cb_button_destroyed, NULL); g_object_set_data_full (priv->button, "::leak-check::", priv->button, (GDestroyNotify)cb_button_disposed); and the functions static void cb_button_disposed (GtkWidget *button) { g_printerr ("Button %p disposed\n", button); } static void cb_button_destroyed (GtkWidget *button) { g_printerr ("Button %p destroyed\n", button); } Running something that uses a treeview I get... welinder@sherwood:~/gnome-src/gtk+/gtk> ../tests/testtreeview Gtk-Message: Failed to load module "canberra-gtk-module" Running automated tests... Passed. Create button 0x20921a0 for column 0x20910b0 Create button 0x2092320 for column 0x2091180 Create button 0x20924a0 for column 0x2091250 Create button 0x2092620 for column 0x2091320 Create button 0x20927a0 for column 0x20913f0 Create button 0x2092920 for column 0x20914c0 welinder@sherwood:~/gnome-src/gtk+/gtk> So not destroyed and not disposed. The button is made an internal child of the treeview, so it is not subject to container's recursive destroy. And nothing else seems to do it. Adding this line to gtk_tree_view_remove_column: gtk_widget_destroy (gtk_tree_view_column_get_button (column)); brings me further: welinder@sherwood:~/gnome-src/gtk+/gtk> ../tests/testtreeview Gtk-Message: Failed to load module "canberra-gtk-module" Running automated tests... Passed. Create button 0xf491a0 for column 0xf478b0 Create button 0xf49320 for column 0xf47980 Create button 0xf494a0 for column 0xf47a50 Create button 0xf49620 for column 0xf47b20 Create button 0xf497a0 for column 0xf47bf0 Create button 0xf49920 for column 0xf47cc0 Button 0xf49920 destroyed Button 0xf491a0 destroyed Button 0xf49320 destroyed Button 0xf494a0 destroyed Button 0xf49620 destroyed Button 0xf497a0 destroyed welinder@sherwood:~/gnome-src/gtk+/gtk> Destroyed, but still not disposed. And I am not sure that fix is right. This is with 3.10.4, but I am not setup to compile anything significantly newer. The leak is not new.
Might be fixed by https://git.gnome.org/browse/gtk+/commit/?id=4f1d9452becc18301b561d4a6fc575cfb4137911
That patch does indeed help a lot, but it is not a full fix: there still isn't anything that triggers the gtk_widget_destroy on the button other than its losing its last ref. When someone else holds a ref to the button it still never gets destroyed and the reffer thus never gets told to release the ref.
Your example now properly disposes the buttons with the fix found incidentally at https://bugzilla.gnome.org/show_bug.cgi?id=788614#c4 If you find any other instances where the buttons are still leaked, please do reopen!