From eed273b35e060e91e3d6e018af62eca6c3782c84 Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Sun, 5 Apr 2009 23:46:15 +0200 Subject: [PATCH] Fix memory leaks in a number of places --- extensions/statusbar-features.c | 1 + katze/katze-net.c | 3 ++- midori/main.c | 12 +++++++++++- midori/midori-array.c | 6 ++++-- panels/midori-addons.c | 1 + panels/midori-bookmarks.c | 17 ++++++++++++++++- panels/midori-history.c | 17 ++++++++++++++++- tests/browser.c | 1 + 8 files changed, 52 insertions(+), 6 deletions(-) diff --git a/extensions/statusbar-features.c b/extensions/statusbar-features.c index d4792299..8eb65c69 100644 --- a/extensions/statusbar-features.c +++ b/extensions/statusbar-features.c @@ -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); diff --git a/katze/katze-net.c b/katze/katze-net.c index c699026d..8a82747b 100644 --- a/katze/katze-net.c +++ b/katze/katze-net.c @@ -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) diff --git a/midori/main.c b/midori/main.c index f15206a7..4152661f 100644 --- a/midori/main.c +++ b/midori/main.c @@ -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); diff --git a/midori/midori-array.c b/midori/midori-array.c index b1ed8750..af53f003 100644 --- a/midori/midori-array.c +++ b/midori/midori-array.c @@ -257,7 +257,8 @@ katze_item_to_data (KatzeItem* item) markup = g_strdup_printf ("\n%s%s%s\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); diff --git a/panels/midori-addons.c b/panels/midori-addons.c index dd987e34..122809e8 100644 --- a/panels/midori-addons.c +++ b/panels/midori-addons.c @@ -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); diff --git a/panels/midori-bookmarks.c b/panels/midori-bookmarks.c index d4150077..a1de10d5 100644 --- a/panels/midori-bookmarks.c +++ b/panels/midori-bookmarks.c @@ -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: * diff --git a/panels/midori-history.c b/panels/midori-history.c index 18718ce4..1bb75fb3 100644 --- a/panels/midori-history.c +++ b/panels/midori-history.c @@ -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: * diff --git a/tests/browser.c b/tests/browser.c index f6b3ee37..1ee15369 100644 --- a/tests/browser.c +++ b/tests/browser.c @@ -43,6 +43,7 @@ browser_create (void) } g_list_free (actions); gtk_widget_destroy (GTK_WIDGET (browser)); + g_object_unref (app); } int -- 2.39.5