[evolution/webkit] Fix some GPtrArray leaks.



commit 3cf9aa34483e9c3047334148a0def6cb2ea27101
Author: Matthew Barnes <mbarnes redhat com>
Date:   Wed May 11 14:44:35 2011 -0400

    Fix some GPtrArray leaks.

 mail/e-mail-folder-pane.c |   22 +++++++++++++------
 mail/e-mail-reader.c      |   51 ++++++++++++++++++++++++++++++--------------
 2 files changed, 50 insertions(+), 23 deletions(-)
---
diff --git a/mail/e-mail-folder-pane.c b/mail/e-mail-folder-pane.c
index 2f1091e..0e55fc5 100644
--- a/mail/e-mail-folder-pane.c
+++ b/mail/e-mail-folder-pane.c
@@ -75,9 +75,14 @@ mail_paned_view_open_selected_mail (EMailPanedView *view)
 	folder = e_mail_reader_get_folder (reader);
 	window = e_mail_reader_get_window (reader);
 	uids = e_mail_reader_get_selected_uids (reader);
+	g_return_val_if_fail (uids != NULL, 0);
+
+	/* XXX Either e_mail_reader_get_selected_uids()
+	 *     or MessageList should do this itself. */
+	g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free);
 
 	if (!em_utils_ask_open_many (window, uids->len)) {
-		em_utils_uids_free (uids);
+		g_ptr_array_unref (uids);
 		return 0;
 	}
 
@@ -85,10 +90,12 @@ mail_paned_view_open_selected_mail (EMailPanedView *view)
 		em_utils_folder_is_outbox (folder) ||
 		em_utils_folder_is_templates (folder)) {
 		em_utils_edit_messages (reader, folder, uids, TRUE);
+		g_ptr_array_unref (uids);
 		return 0;
 	}
 
-	views = g_ptr_array_new ();
+	views = g_ptr_array_new_with_free_func ((GDestroyNotify) g_free);
+
 	/* For vfolders we need to edit the original, not the vfolder copy. */
 	for (ii = 0; ii < uids->len; ii++) {
 		const gchar *uid = uids->pdata[ii];
@@ -113,10 +120,12 @@ mail_paned_view_open_selected_mail (EMailPanedView *view)
 			em_utils_folder_is_outbox (real_folder)) {
 			GPtrArray *edits;
 
-			edits = g_ptr_array_new ();
+			edits = g_ptr_array_new_with_free_func (
+				(GDestroyNotify) g_free);
 			g_ptr_array_add (edits, real_uid);
 			em_utils_edit_messages (
 				reader, real_folder, edits, TRUE);
+			g_ptr_array_unref (edits);
 		} else {
 			g_free (real_uid);
 			g_ptr_array_add (views, g_strdup (uid));
@@ -126,13 +135,12 @@ mail_paned_view_open_selected_mail (EMailPanedView *view)
 	}
 
 	n_views = views->len;
+
 	for (i = 0; i < n_views; i++)
 		g_signal_emit_by_name (view, "open-mail", views->pdata[i]);
 
-	g_ptr_array_foreach (views, (GFunc) g_free, NULL);
-	g_ptr_array_free (views, TRUE);
-
-	em_utils_uids_free (uids);
+	g_ptr_array_unref (views);
+	g_ptr_array_unref (uids);
 
 	return n_views;
 }
diff --git a/mail/e-mail-reader.c b/mail/e-mail-reader.c
index e18a546..8cca498 100644
--- a/mail/e-mail-reader.c
+++ b/mail/e-mail-reader.c
@@ -541,17 +541,20 @@ action_mail_forward_cb (GtkAction *action,
 	GPtrArray *uids;
 
 	folder = e_mail_reader_get_folder (reader);
-	uids = e_mail_reader_get_selected_uids (reader);
 	window = e_mail_reader_get_window (reader);
-
+	uids = e_mail_reader_get_selected_uids (reader);
 	g_return_if_fail (uids != NULL);
 
+	/* XXX Either e_mail_reader_get_selected_uids()
+	 *     or MessageList should do this itself. */
+	g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free);
+
 	if (em_utils_ask_open_many (window, uids->len))
 		em_utils_forward_messages (
 			reader, folder, uids,
 			e_mail_reader_get_forward_style (reader));
-	else
-		em_utils_uids_free (uids);
+
+	g_ptr_array_unref (uids);
 
 	check_close_browser_reader (reader);
 }
@@ -565,17 +568,20 @@ action_mail_forward_attached_cb (GtkAction *action,
 	GPtrArray *uids;
 
 	folder = e_mail_reader_get_folder (reader);
-	uids = e_mail_reader_get_selected_uids (reader);
 	window = e_mail_reader_get_window (reader);
-
+	uids = e_mail_reader_get_selected_uids (reader);
 	g_return_if_fail (uids != NULL);
 
+	/* XXX Either e_mail_reader_get_selected_uids()
+	 *     or MessageList should do this itself. */
+	g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free);
+
 	if (em_utils_ask_open_many (window, uids->len))
 		em_utils_forward_messages (
 			reader, folder, uids,
 			E_MAIL_FORWARD_STYLE_ATTACHED);
-	else
-		em_utils_uids_free (uids);
+
+	g_ptr_array_unref (uids);
 
 	check_close_browser_reader (reader);
 }
@@ -589,17 +595,20 @@ action_mail_forward_inline_cb (GtkAction *action,
 	GPtrArray *uids;
 
 	folder = e_mail_reader_get_folder (reader);
-	uids = e_mail_reader_get_selected_uids (reader);
 	window = e_mail_reader_get_window (reader);
-
+	uids = e_mail_reader_get_selected_uids (reader);
 	g_return_if_fail (uids != NULL);
 
+	/* XXX Either e_mail_reader_get_selected_uids()
+	 *     or MessageList should do this itself. */
+	g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free);
+
 	if (em_utils_ask_open_many (window, uids->len))
 		em_utils_forward_messages (
 			reader, folder, uids,
 			E_MAIL_FORWARD_STYLE_INLINE);
-	else
-		em_utils_uids_free (uids);
+
+	g_ptr_array_unref (uids);
 
 	check_close_browser_reader (reader);
 }
@@ -613,17 +622,20 @@ action_mail_forward_quoted_cb (GtkAction *action,
 	GPtrArray *uids;
 
 	folder = e_mail_reader_get_folder (reader);
-	uids = e_mail_reader_get_selected_uids (reader);
 	window = e_mail_reader_get_window (reader);
-
+	uids = e_mail_reader_get_selected_uids (reader);
 	g_return_if_fail (uids != NULL);
 
+	/* XXX Either e_mail_reader_get_selected_uids()
+	 *     or MessageList should do this itself. */
+	g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free);
+
 	if (em_utils_ask_open_many (window, uids->len))
 		em_utils_forward_messages (
 			reader, folder, uids,
 			E_MAIL_FORWARD_STYLE_QUOTED);
-	else
-		em_utils_uids_free (uids);
+
+	g_ptr_array_unref (uids);
 
 	check_close_browser_reader (reader);
 }
@@ -731,9 +743,16 @@ action_mail_message_edit_cb (GtkAction *action,
 
 	folder = e_mail_reader_get_folder (reader);
 	uids = e_mail_reader_get_selected_uids (reader);
+	g_return_if_fail (uids != NULL);
+
+	/* XXX Either e_mail_reader_get_selected_uids()
+	 *     or MessageList should do this itself. */
+	g_ptr_array_set_free_func (uids, (GDestroyNotify) g_free);
 
 	replace = em_utils_folder_is_drafts (folder);
 	em_utils_edit_messages (reader, folder, uids, replace);
+
+	g_ptr_array_unref (uids);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]