Bug 476805. Stop leak by avoiding double refs. r+sr=roc
authorArpad Borsos <arpad.borsos@googlemail.com>
Wed, 04 Feb 2009 14:21:02 +0100
changeset 24665 85c60136c66db7080d96a724d192948b0aeebb3d
parent 24664 48bf047a9054fec8a01338fa4264035f7172b14b
child 24666 c53c81f1906348af1780a3bc3124b0f6930a9c8a
push idunknown
push userunknown
push dateunknown
bugs476805
milestone1.9.2a1pre
Bug 476805. Stop leak by avoiding double refs. r+sr=roc
gfx/src/thebes/nsSystemFontsGTK2.cpp
widget/src/gtk2/nsLookAndFeel.cpp
widget/src/gtk2/nsLookAndFeel.h
--- a/gfx/src/thebes/nsSystemFontsGTK2.cpp
+++ b/gfx/src/thebes/nsSystemFontsGTK2.cpp
@@ -149,17 +149,16 @@ nsSystemFontsGTK2::nsSystemFontsGTK2()
     GetSystemFontInfo(entry, &mFieldFontName, &mFieldFontStyle);
 
     gtk_widget_destroy(window);  // no unref, windows are different
 
     // mMenuFont
     GtkWidget *accel_label = gtk_accel_label_new("M");
     GtkWidget *menuitem = gtk_menu_item_new();
     GtkWidget *menu = gtk_menu_new();
-    g_object_ref(GTK_OBJECT(menu));
     g_object_ref_sink(GTK_OBJECT(menu));
 
     gtk_container_add(GTK_CONTAINER(menuitem), accel_label);
     gtk_menu_shell_append((GtkMenuShell *)GTK_MENU(menu), menuitem);
 
     gtk_widget_ensure_style(accel_label);
 
     GetSystemFontInfo(accel_label, &mMenuFontName, &mMenuFontStyle);
--- a/widget/src/gtk2/nsLookAndFeel.cpp
+++ b/widget/src/gtk2/nsLookAndFeel.cpp
@@ -407,17 +407,16 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(c
         // XXXldb Why is this commented out?
         //    aMetric = 4;
         break;
     case eMetric_TextFieldHeight:
         {
             GtkRequisition req;
             GtkWidget *text = gtk_entry_new();
             // needed to avoid memory leak
-            g_object_ref(text);
             g_object_ref_sink(GTK_OBJECT(text));
             gtk_widget_size_request(text,&req);
             aMetric = req.height;
             gtk_widget_destroy(text);
             g_object_unref(text);
         }
         break;
     case eMetric_TextFieldBorder:
@@ -485,17 +484,16 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(c
         break;
     case eMetric_SelectTextfieldsOnKeyFocus:
         {
             GtkWidget *entry;
             GtkSettings *settings;
             gboolean select_on_focus;
 
             entry = gtk_entry_new();
-            g_object_ref(entry);
             g_object_ref_sink(GTK_OBJECT(entry));
             settings = gtk_widget_get_settings(entry);
             g_object_get(settings, 
                          "gtk-entry-select-on-focus",
                          &select_on_focus,
                          NULL);
             
             if(select_on_focus)
@@ -531,16 +529,17 @@ NS_IMETHODIMP nsLookAndFeel::GetMetric(c
     case eMetric_DragThresholdY:
         {
             GtkWidget* box = gtk_hbox_new(FALSE, 5);
             gint threshold = 0;
             g_object_get(gtk_widget_get_settings(box),
                          "gtk-dnd-drag-threshold", &threshold,
                          NULL);
             g_object_ref_sink(GTK_OBJECT(box));
+            
             aMetric = threshold;
         }
         break;
     case eMetric_ScrollArrowStyle:
         aMetric =
             ConvertGTKStepperStyleToMozillaScrollArrowStyle(moz_gtk_get_scrollbar_widget());
         break;
     case eMetric_ScrollSliderStyle:
@@ -650,17 +649,16 @@ nsLookAndFeel::InitLookAndFeel()
         sInfoBackground = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]);
         sInfoText = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
     }
 
     // menu foreground & menu background
     GtkWidget *accel_label = gtk_accel_label_new("M");
     GtkWidget *menuitem = gtk_menu_item_new();
     GtkWidget *menu = gtk_menu_new();
-    g_object_ref(GTK_OBJECT(menu));
     g_object_ref_sink(GTK_OBJECT(menu));
 
     gtk_container_add(GTK_CONTAINER(menuitem), accel_label);
     gtk_menu_shell_append((GtkMenuShell *)GTK_MENU(menu), menuitem);
 
     gtk_widget_set_style(accel_label, NULL);
     gtk_widget_set_style(menu, NULL);
     gtk_widget_realize(menu);
--- a/widget/src/gtk2/nsLookAndFeel.h
+++ b/widget/src/gtk2/nsLookAndFeel.h
@@ -76,16 +76,15 @@ protected:
     static nscolor sComboBoxText;
     static nscolor sComboBoxBackground;
     static PRUnichar sInvisibleCharacter;
     static float   sCaretRatio;
 
     static void InitLookAndFeel();
     void InitWidget() {
         mWidget = gtk_invisible_new();
-        g_object_ref(GTK_OBJECT(mWidget));
         g_object_ref_sink(GTK_OBJECT(mWidget));
         gtk_widget_ensure_style(mWidget);
         mStyle = gtk_widget_get_style(mWidget);
     }
 };
 
 #endif