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 774066 - GtkHeaderBar does not unref all GtkBox and GtkSeparator it creates
GtkHeaderBar does not unref all GtkBox and GtkSeparator it creates
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
3.22.x
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2016-11-07 16:24 UTC by Massimo
Modified: 2016-11-10 20:04 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Massimo 2016-11-07 16:24:53 UTC
After setting GOBJECT_DEBUG=objects comparing the outputs                
of the following program run with ITERATIONS set to 2 and 1:             
                                                                         
#include <gtk/gtk.h>                                                     
                                                                         
#ifndef ITERATIONS                                                       
#define ITERATIONS 2                                                     
#endif                                                                   
                                                                         
int                                                                      
main (int   argc,                                                        
      char *argv[])                                                      
{                                                                        
  if (gtk_init_check (&argc, &argv))                                     
    for (gint i = 0; i < ITERATIONS; ++i)                                
      {                                                                  
        GtkWidget *dialog = gtk_color_chooser_dialog_new ("Open File",   
                                                          NULL);         
        gtk_dialog_run (GTK_DIALOG (dialog));                            
                                                                         
        gtk_widget_destroy (dialog);                                     
      }                                                                  
                                                                         
  return 0;                                                              
}                                                                        
                                                                         
                                                                         
the number of objects alive at exit increases for the presence           
of few GtkBox and GtkSeparator created by GtkHeaderBar.                  
                                                                         
in                                                                       
                                                                         
https://git.gnome.org/browse/gtk+/tree/gtk/gtkheaderbar.c?h=gtk-3-22#n340
                                                                         
a GtkBox and a GtkSeparator are created and when they're not             
necessary they're destroyed:                                             
                                                                         
https://git.gnome.org/browse/gtk+/tree/gtk/gtkheaderbar.c?h=gtk-3-22#n458
                                                                         
but that's not enough, apparently to remove the last reference           
from a widget not inserted in a parent widget it is necessary            
to                                                                       
                                                                         
g_object_unref (g_object_ref_sink (box/separator));                      
                                                                         
                                                                         
In this case it is probably simpler to initialize 'box' = NULL           
and get rid of the variable 'n_children'. When that var would be         
incremented to 1 create 'box' and 'separator' and after the loop         
continue if 'box' is still NULL.