changeset 22840:502bac8b2b4c

Fix a double free caused by my previous leak fix not covering all possible situations - pidgin_notify_add_mail() may return a newly allocated structure or a reused one.
author Daniel Atallah <daniel.atallah@gmail.com>
date Thu, 08 May 2008 00:22:08 +0000
parents 4f65a1983a0a
children 10fb6ced9bc8 f9fd7ddf6996
files pidgin/gtknotify.c
diffstat 1 files changed, 19 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtknotify.c	Wed May 07 21:18:50 2008 +0000
+++ b/pidgin/gtknotify.c	Thu May 08 00:22:08 2008 +0000
@@ -425,7 +425,7 @@
  * count > 0 mean non-detailed.
  */
 static void *
-pidgin_notify_add_mail(GtkTreeStore *treemodel, PurpleAccount *account, char *notification, const char *url, int count, gboolean clear)
+pidgin_notify_add_mail(GtkTreeStore *treemodel, PurpleAccount *account, char *notification, const char *url, int count, gboolean clear, gboolean *new_data)
 {
 	PidginNotifyMailData *data = NULL;
 	GtkTreeIter iter;
@@ -492,6 +492,9 @@
 						PIDGIN_MAIL_DATA, &data, -1);
 	if (icon)
 		g_object_unref(icon);
+
+	if (new_data)
+		*new_data = new_n;
 	return data;
 }
 
@@ -503,7 +506,8 @@
 	GtkWidget *dialog = NULL;
 	char *notification;
 	PurpleAccount *account;
-	PidginNotifyMailData *data = NULL;
+	PidginNotifyMailData *data = NULL, *data2;
+	gboolean new_data;
 
 	/* Don't bother updating if there aren't new emails and we don't have any displayed currently */
 	if (count == 0 && mail_dialog == NULL)
@@ -550,9 +554,12 @@
 			g_free(subject_text);
 
 			/* If we don't keep track of this, will leak "data" for each of the notifications except the last */
-			if (data)
-				data->purple_has_handle = FALSE;
-			data = pidgin_notify_add_mail(mail_dialog->treemodel, account, notification, urls ? *urls : NULL, 0, FALSE);
+			data2 = pidgin_notify_add_mail(mail_dialog->treemodel, account, notification, urls ? *urls : NULL, 0, FALSE, &new_data);
+			if (new_data) {
+				if (data)
+					data->purple_has_handle = FALSE;
+				data = data2;
+			}
 			g_free(notification);
 
 			if (urls != NULL)
@@ -564,13 +571,18 @@
 							   "%s has %d new messages.",
 							   (int)count),
 							   *tos, (int)count);
-			data = pidgin_notify_add_mail(mail_dialog->treemodel, account, notification, urls ? *urls : NULL, count, FALSE);
+			data2 = pidgin_notify_add_mail(mail_dialog->treemodel, account, notification, urls ? *urls : NULL, count, FALSE, &new_data);
+			if (new_data) {
+				if (data)
+					data->purple_has_handle = FALSE;
+				data = data2;
+			}
 			g_free(notification);
 		} else {
 			GtkTreeIter iter;
 
 			/* Clear out all mails for the account */
-			pidgin_notify_add_mail(mail_dialog->treemodel, account, NULL, NULL, 0, TRUE);
+			pidgin_notify_add_mail(mail_dialog->treemodel, account, NULL, NULL, 0, TRUE, NULL);
 
 			if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(mail_dialog->treemodel), &iter)) {
 				/* There is no API to clear the headline specifically */