]> spindle.queued.net Git - midori/commitdiff
Fix memory leaks in a number of places
authorChristian Dywan <christian@twotoasts.de>
Sun, 5 Apr 2009 21:46:15 +0000 (23:46 +0200)
committerChristian Dywan <christian@twotoasts.de>
Sun, 5 Apr 2009 21:46:15 +0000 (23:46 +0200)
extensions/statusbar-features.c
katze/katze-net.c
midori/main.c
midori/midori-array.c
panels/midori-addons.c
panels/midori-bookmarks.c
panels/midori-history.c
tests/browser.c

index d47922991d1a2addd8c0ebeb96202aef0a964d88..8eb65c69543cf07a977ef0fcd17a28633e5c58f1 100644 (file)
@@ -68,6 +68,7 @@ statusbar_features_app_add_browser_cb (MidoriApp*       app,
     gtk_widget_show (button);
     gtk_widget_show (bbox);
     gtk_box_pack_start (GTK_BOX (statusbar), bbox, FALSE, FALSE, 3);
+    g_object_unref (settings);
 
     g_signal_connect (extension, "deactivate",
         G_CALLBACK (statusbar_features_deactivate_cb), bbox);
index c699026d7f100a45b7d7a4e3ef142b597e7e7926..8a82747b11f337834993113db8eabcf91b014caf 100644 (file)
@@ -557,11 +557,12 @@ katze_net_load_icon (KatzeNet*      net,
         if (g_hash_table_lookup_extended (net->memory,
                                           icon_file, NULL, (gpointer)&pixbuf))
         {
+            g_free (icon_file);
             if (pixbuf)
                 g_object_ref (pixbuf);
         }
         else if ((pixbuf = gdk_pixbuf_new_from_file (icon_file, NULL)))
-            ;
+            g_free (icon_file);
         /* If the called doesn't provide an icon callback,
            we assume there is no interest in loading an un-cached icon. */
         else if (icon_cb)
index f15206a71848838f7f9c62393f029e0a0b7e823e..4152661fd272007f070ac6fdd7986ce9a658c166 100644 (file)
@@ -154,6 +154,7 @@ settings_new_from_file (const gchar* filename)
         else
             g_warning (_("Invalid configuration value '%s'"), property);
     }
+    g_free (pspecs);
     return settings;
 }
 
@@ -188,10 +189,11 @@ settings_save_to_file (MidoriWebSettings* settings,
         }
         if (type == G_TYPE_PARAM_STRING)
         {
-            const gchar* string;
+            gchar* string;
             g_object_get (settings, property, &string, NULL);
             g_key_file_set_string (key_file, "settings", property,
                                    string ? string : "");
+            g_free (string);
         }
         else if (type == G_TYPE_PARAM_INT)
         {
@@ -224,6 +226,7 @@ settings_save_to_file (MidoriWebSettings* settings,
         else
             g_warning (_("Invalid configuration value '%s'"), property);
     }
+    g_free (pspecs);
     saved = sokoke_key_file_save_to_file (key_file, filename, error);
     g_key_file_free (key_file);
     return saved;
@@ -266,6 +269,7 @@ search_engines_new_from_file (const gchar* filename,
         }
         katze_array_add_item (search_engines, item);
     }
+    g_free (pspecs);
     g_strfreev (engines);
     g_key_file_free (key_file);
     return search_engines;
@@ -303,6 +307,7 @@ search_engines_save_to_file (KatzeArray*  search_engines,
             g_free (value);
         }
     }
+    g_free (pspecs);
     saved = sokoke_key_file_save_to_file (key_file, filename, error);
     g_key_file_free (key_file);
 
@@ -921,6 +926,8 @@ midori_app_add_browser_cb (MidoriApp*     app,
     addon = g_object_new (MIDORI_TYPE_EXTENSIONS, "app", app, NULL);
     gtk_widget_show (addon);
     midori_panel_append_page (MIDORI_PANEL (panel), MIDORI_VIEWABLE (addon));
+
+    g_object_unref (panel);
 }
 
 static void
@@ -1241,7 +1248,9 @@ midori_load_session (gpointer data)
             katze_item_set_uri (item, homepage);
             g_free (homepage);
         }
+        g_object_unref (settings);
         katze_array_add_item (_session, item);
+        g_object_unref (item);
     }
 
     session = midori_browser_get_proxy_array (browser);
@@ -1682,6 +1691,7 @@ main (int    argc,
     #if HAVE_SQLITE
     settings = katze_object_get_object (app, "settings");
     g_object_get (settings, "maximum-history-age", &max_history_age, NULL);
+    g_object_unref (settings);
     midori_history_terminate (db, max_history_age);
     #endif
     g_object_unref (app);
index b1ed8750a7c96540bf8a7006d979b67d3dbdf095..af53f003393554a9538f35dd4d987cd6d880580c 100644 (file)
@@ -257,7 +257,8 @@ katze_item_to_data (KatzeItem* item)
         markup = g_strdup_printf ("<folder%s>\n%s%s%s</folder>\n",
                                   "" /* folded ? folded : "" */,
                                   title, desc,
-                                  g_string_free (_markup, FALSE));
+                                  _markup->str);
+        g_string_free (_markup, TRUE);
         /* g_free (folded); */
         g_free (title);
         g_free (desc);
@@ -313,7 +314,8 @@ katze_array_to_xbel (KatzeArray* array,
                    "\"http://www.python.org/topics/xml/dtds/xbel-1.0.dtd\">\n",
                    title,
                    desc,
-                   g_string_free (inner_markup, FALSE));
+                   inner_markup->str);
+    g_string_free (inner_markup, TRUE);
     g_free (title);
     g_free (desc);
 
index dd987e3419c29e80f0a014bedb4f87b6491e22ea..122809e813664cbb48a743542fe77f21f686a638 100644 (file)
@@ -883,6 +883,7 @@ midori_addons_new (MidoriAddonKind kind,
         }
         g_signal_connect (monitor, "changed",
             G_CALLBACK (midori_addons_directory_monitor_changed), addons);
+        g_object_unref (directory);
     }
     g_slist_free (list);
 
index d4150077661e402a0ff6a9b27287b978b26c7552..a1de10d56d076a599f7637d5a58256ac5059cb0b 100644 (file)
@@ -63,6 +63,9 @@ enum
     PROP_APP
 };
 
+static void
+midori_bookmarks_finalize     (GObject* object);
+
 static void
 midori_bookmarks_set_property (GObject*      object,
                                guint         prop_id,
@@ -82,6 +85,7 @@ midori_bookmarks_class_init (MidoriBookmarksClass* class)
     GParamFlags flags;
 
     gobject_class = G_OBJECT_CLASS (class);
+    gobject_class->finalize = midori_bookmarks_finalize;
     gobject_class->set_property = midori_bookmarks_set_property;
     gobject_class->get_property = midori_bookmarks_get_property;
 
@@ -691,6 +695,7 @@ midori_bookmarks_open_in_tab_activate_cb (GtkWidget*       menuitem,
                 settings = katze_object_get_object (browser, "settings");
                 if (!katze_object_get_boolean (settings, "open-tabs-in-the-background"))
                     midori_browser_set_current_page (MIDORI_BROWSER (browser), n);
+                g_object_unref (settings);
             }
             i++;
         }
@@ -707,6 +712,7 @@ midori_bookmarks_open_in_tab_activate_cb (GtkWidget*       menuitem,
             settings = katze_object_get_object (browser, "settings");
             if (!katze_object_get_boolean (settings, "open-tabs-in-the-background"))
                 midori_browser_set_current_page (MIDORI_BROWSER (browser), n);
+            g_object_unref (settings);
         }
     }
 }
@@ -888,7 +894,6 @@ midori_bookmarks_init (MidoriBookmarks* bookmarks)
     GtkCellRenderer* renderer_text;
 
     bookmarks->net = katze_net_new ();
-    /* FIXME: Dereference the net on finalization */
 
     /* Create the treeview */
     model = gtk_tree_store_new (1, KATZE_TYPE_ITEM);
@@ -926,6 +931,16 @@ midori_bookmarks_init (MidoriBookmarks* bookmarks)
     bookmarks->treeview = treeview;
 }
 
+static void
+midori_bookmarks_finalize (GObject* object)
+{
+    MidoriBookmarks* bookmarks = MIDORI_BOOKMARKS (object);
+
+    if (bookmarks->app)
+        g_object_unref (bookmarks->app);
+    g_object_unref (bookmarks->net);
+}
+
 /**
  * midori_bookmarks_new:
  *
index 18718ce417e204ebf77aaae5235de9b4aa00eea9..1bb75fb300288a9c449d8ce84235c600ec437e3e 100644 (file)
@@ -64,6 +64,9 @@ enum
     PROP_APP
 };
 
+static void
+midori_history_finalize     (GObject*      object);
+
 static void
 midori_history_set_property (GObject*      object,
                              guint         prop_id,
@@ -83,6 +86,7 @@ midori_history_class_init (MidoriHistoryClass* class)
     GParamFlags flags;
 
     gobject_class = G_OBJECT_CLASS (class);
+    gobject_class->finalize = midori_history_finalize;
     gobject_class->set_property = midori_history_set_property;
     gobject_class->get_property = midori_history_get_property;
 
@@ -495,7 +499,6 @@ midori_history_set_app (MidoriHistory* history,
         time_t now = time (NULL);
         gint64 day = sokoke_time_t_to_julian (&now);
 
-        /* FIXME: Dereference the app on finalization */
         model = gtk_tree_view_get_model (GTK_TREE_VIEW (history->treeview));
         midori_history_insert_item (history, GTK_TREE_STORE (model),
             NULL, KATZE_ITEM (g_object_ref (history->array)), day);
@@ -721,6 +724,7 @@ midori_history_open_in_tab_activate_cb (GtkWidget*     menuitem,
                 settings = katze_object_get_object (browser, "settings");
                 if (!katze_object_get_boolean (settings, "open-tabs-in-the-background"))
                     midori_browser_set_current_page (MIDORI_BROWSER (browser), n);
+                g_object_unref (settings);
             }
             i++;
         }
@@ -737,6 +741,7 @@ midori_history_open_in_tab_activate_cb (GtkWidget*     menuitem,
             settings = katze_object_get_object (browser, "settings");
             if (!katze_object_get_boolean (settings, "open-tabs-in-the-background"))
                 midori_browser_set_current_page (MIDORI_BROWSER (browser), n);
+            g_object_unref (settings);
         }
     }
 }
@@ -957,6 +962,16 @@ midori_history_init (MidoriHistory* history)
     history->treeview = treeview;
 }
 
+static void
+midori_history_finalize (GObject* object)
+{
+    MidoriHistory* history = MIDORI_HISTORY (object);
+
+    if (history->app)
+        g_object_unref (history->app);
+    g_object_unref (history->array);
+}
+
 /**
  * midori_history_new:
  *
index f6b3ee37586c236161fd5c14439055ed680d5767..1ee1536986131949f15f064a11fdb0019a30961f 100644 (file)
@@ -43,6 +43,7 @@ browser_create (void)
     }
     g_list_free (actions);
     gtk_widget_destroy (GTK_WIDGET (browser));
+    g_object_unref (app);
 }
 
 int