From c9e57de8d67594c4ffae439f27502b68729b55aa Mon Sep 17 00:00:00 2001 From: Christian Dywan Date: Sat, 2 Aug 2008 04:25:54 +0200 Subject: [PATCH] Scruffily clean up MidoriWebList when finalizing --- midori/midori-weblist.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/midori/midori-weblist.c b/midori/midori-weblist.c index 18f0d979..8eb50a6c 100644 --- a/midori/midori-weblist.c +++ b/midori/midori-weblist.c @@ -102,8 +102,12 @@ static void midori_web_list_finalize (GObject* object) { MidoriWebList* web_list = MIDORI_WEB_LIST (object); + guint n, i; - midori_web_list_clear (web_list); + /* Scruffily remove all items, no need for signals */ + n = g_list_length (web_list->items); + for (i = 0; i < n; i++) + g_object_unref (g_list_nth_data (web_list->items, i)); g_list_free (web_list->items); G_OBJECT_CLASS (midori_web_list_parent_class)->finalize (object); @@ -136,6 +140,7 @@ void midori_web_list_add_item (MidoriWebList* web_list, gpointer item) { + g_return_if_fail (MIDORI_IS_WEB_LIST (web_list)); g_return_if_fail (G_IS_OBJECT (item)); g_signal_emit (web_list, signals[ADD_ITEM], 0, item); @@ -152,6 +157,7 @@ void midori_web_list_remove_item (MidoriWebList* web_list, gpointer item) { + g_return_if_fail (MIDORI_IS_WEB_LIST (web_list)); g_return_if_fail (G_IS_OBJECT (item)); g_signal_emit (web_list, signals[REMOVE_ITEM], 0, item); @@ -271,13 +277,18 @@ midori_web_list_get_length (MidoriWebList* web_list) void midori_web_list_clear (MidoriWebList* web_list) { + guint n; + guint i; + GObject* item; + g_return_if_fail (MIDORI_IS_WEB_LIST (web_list)); - guint n = g_list_length (web_list->items); - guint i; + n = g_list_length (web_list->items); for (i = 0; i < n; i++) { - GObject* item = g_list_nth_data (web_list->items, i); - midori_web_list_remove_item (web_list, item); + if ((item = g_list_nth_data (web_list->items, i))) + midori_web_list_remove_item (web_list, item); } + g_list_free (web_list->items); + web_list->items = NULL; }