# HG changeset patch # User Daniel Atallah # Date 1210206128 0 # Node ID 502bac8b2b4c2bbef713af5f2cea07798b216ef4 # Parent 4f65a1983a0ad86a3f1d6ce38a4f85e765747896 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. diff -r 4f65a1983a0a -r 502bac8b2b4c pidgin/gtknotify.c --- 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 */