[balsa] Use g_{,s}list_free_full()



commit 2308670f29cf350935256ec1a973805af17618c2
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Wed Jun 12 21:11:44 2019 -0400

    Use g_{,s}list_free_full()
    
    instead of g_{,s}list_foreach() with a GDestroyFunc cast to GFunc,
    followed by g{,s}list_free(). Avoids many -Wcast-function-type warnings.

 libbalsa/address-book-ldif.c  |  5 ++---
 libbalsa/address-view.c       |  3 +--
 libbalsa/filter-funcs.c       |  3 +--
 libbalsa/folder-scanners.c    |  3 +--
 libbalsa/identity.c           |  3 +--
 libbalsa/imap-server.c        | 15 ++++++++-------
 libbalsa/mailbox.c            |  3 +--
 libbalsa/mailbox_imap.c       |  3 +--
 libbalsa/mailbox_local.c      |  3 +--
 libbalsa/message.c            |  9 +++------
 libbalsa/message.h            |  3 +--
 libbalsa/rfc2445.c            |  6 ++----
 libbalsa/send.c               |  3 +--
 src/balsa-app.c               | 15 +++++----------
 src/balsa-index.c             |  3 +--
 src/balsa-mblist.c            |  6 ++----
 src/balsa-mime-widget-text.c  |  3 +--
 src/balsa-print-object-text.c |  6 ++----
 src/filter-edit-callbacks.c   |  6 ++----
 src/filter-run-callbacks.c    |  3 +--
 src/main-window.c             |  3 +--
 src/print-gtk.c               |  3 +--
 src/sendmsg-window.c          | 15 +++++----------
 src/store-address.c           |  3 +--
 24 files changed, 46 insertions(+), 82 deletions(-)
---
diff --git a/libbalsa/address-book-ldif.c b/libbalsa/address-book-ldif.c
index f17e3a189..34a2dd675 100644
--- a/libbalsa/address-book-ldif.c
+++ b/libbalsa/address-book-ldif.c
@@ -424,9 +424,8 @@ libbalsa_address_book_ldif_parse_address(FILE * stream,
                     g_free(line);
                     return LBABERR_OK;
                 }
-                g_list_foreach(address_list, (GFunc) g_free, NULL);
-                g_list_free(address_list);
-           } 
+                g_list_free_full(address_list, g_free);
+           }
             /* Record without e-mail address, or we're not creating
              * addresses: free memory. */
             g_free(fullname);
diff --git a/libbalsa/address-view.c b/libbalsa/address-view.c
index 9f6e99dc6..445710be1 100644
--- a/libbalsa/address-view.c
+++ b/libbalsa/address-view.c
@@ -763,8 +763,7 @@ lbav_focus_out_cb(GtkEntry * entry, GdkEventFocus * event,
                 gtk_cell_editable_editing_done(GTK_CELL_EDITABLE(entry));
                 g_free(the_addr);
             }
-            g_list_foreach(match, (GFunc) g_object_unref, NULL);
-            g_list_free(match);
+            g_list_free_full(match, g_object_unref);
         }
     }
 
diff --git a/libbalsa/filter-funcs.c b/libbalsa/filter-funcs.c
index 859c8b127..f1ce3d76e 100644
--- a/libbalsa/filter-funcs.c
+++ b/libbalsa/filter-funcs.c
@@ -501,8 +501,7 @@ void
 regexs_free(GSList * regexs)
 {
     if (regexs) {
-       g_slist_foreach(regexs, (GFunc) libbalsa_condition_regex_free, NULL);
-       g_slist_free(regexs);
+       g_slist_free_full(regexs, (GDestroyNotify) libbalsa_condition_regex_free);
     }
 }                               /* end condition_free_regexs() */
 
diff --git a/libbalsa/folder-scanners.c b/libbalsa/folder-scanners.c
index 66d7608ff..f93e080c7 100644
--- a/libbalsa/folder-scanners.c
+++ b/libbalsa/folder-scanners.c
@@ -380,8 +380,7 @@ libbalsa_imap_browse(const gchar * path, struct browser_state *state,
 
     --*depth;
 
-    g_list_foreach(list, (GFunc) g_free, NULL);
-    g_list_free(list);
+    g_list_free_full(list, g_free);
     return ret;
 }
 
diff --git a/libbalsa/identity.c b/libbalsa/identity.c
index d6fc2a515..2aee60899 100644
--- a/libbalsa/identity.c
+++ b/libbalsa/identity.c
@@ -1629,8 +1629,7 @@ help_ident_cb(GtkWidget * widget)
 static void
 lbi_free_smtp_server_list(GSList ** smtp_server_list)
 {
-    g_slist_foreach(*smtp_server_list, (GFunc) g_object_unref, NULL);
-    g_slist_free(*smtp_server_list);
+    g_slist_free_full(*smtp_server_list, g_object_unref);
     g_free(smtp_server_list);
 }
 
diff --git a/libbalsa/imap-server.c b/libbalsa/imap-server.c
index 39aab2e59..a69112976 100644
--- a/libbalsa/imap-server.c
+++ b/libbalsa/imap-server.c
@@ -725,15 +725,16 @@ libbalsa_imap_server_has_persistent_cache(LibBalsaImapServer *srv)
 void
 libbalsa_imap_server_force_disconnect(LibBalsaImapServer *imap_server)
 {
-       g_mutex_lock(&imap_server->lock);
-    g_list_foreach(imap_server->used_handles,
-                   (GFunc) lb_imap_server_info_free, NULL);
-    g_list_free(imap_server->used_handles);
+    g_mutex_lock(&imap_server->lock);
+
+    g_list_free_full(imap_server->used_handles,
+                   (GDestroyNotify) lb_imap_server_info_free);
     imap_server->used_handles = NULL;
-    g_list_foreach(imap_server->free_handles,
-                   (GFunc) lb_imap_server_info_free, NULL);
-    g_list_free(imap_server->free_handles);
+
+    g_list_free_full(imap_server->free_handles,
+                   (GDestroyNotify) lb_imap_server_info_free);
     imap_server->free_handles = NULL;
+
     g_mutex_unlock(&imap_server->lock);
 }
 
diff --git a/libbalsa/mailbox.c b/libbalsa/mailbox.c
index 9c7dcce37..68bb42cc8 100644
--- a/libbalsa/mailbox.c
+++ b/libbalsa/mailbox.c
@@ -450,8 +450,7 @@ libbalsa_mailbox_finalize(GObject * object)
     libbalsa_condition_unref(mailbox->persistent_view_filter);
     mailbox->persistent_view_filter = NULL;
 
-    g_slist_foreach(mailbox->filters, (GFunc) g_free, NULL);
-    g_slist_free(mailbox->filters);
+    g_slist_free_full(mailbox->filters, g_free);
     mailbox->filters = NULL;
     mailbox->filters_loaded = FALSE;
 
diff --git a/libbalsa/mailbox_imap.c b/libbalsa/mailbox_imap.c
index 1203fcb23..1d351af43 100644
--- a/libbalsa/mailbox_imap.c
+++ b/libbalsa/mailbox_imap.c
@@ -335,8 +335,7 @@ libbalsa_mailbox_imap_finalize(GObject * object)
         mailbox->unread_update_id = 0;
     }
 
-    g_list_foreach(mailbox->acls, (GFunc)imap_user_acl_free, NULL);
-    g_list_free(mailbox->acls);
+    g_list_free_full(mailbox->acls, (GDestroyNotify) imap_user_acl_free);
 
     if (G_OBJECT_CLASS(parent_class)->finalize)
        G_OBJECT_CLASS(parent_class)->finalize(object);
diff --git a/libbalsa/mailbox_local.c b/libbalsa/mailbox_local.c
index daf4e589f..d32fd346f 100644
--- a/libbalsa/mailbox_local.c
+++ b/libbalsa/mailbox_local.c
@@ -372,8 +372,7 @@ lbm_local_free_info(LibBalsaMailboxLocalInfo * info)
 {
     if (info) {
         g_free(info->message_id);
-        g_list_foreach(info->refs_for_threading, (GFunc) g_free, NULL);
-        g_list_free(info->refs_for_threading);
+        g_list_free_full(info->refs_for_threading, g_free);
         g_free(info->sender);
         g_free(info);
     }
diff --git a/libbalsa/message.c b/libbalsa/message.c
index c4642351e..2f56e104b 100644
--- a/libbalsa/message.c
+++ b/libbalsa/message.c
@@ -150,12 +150,10 @@ libbalsa_message_finalize(GObject * object)
     g_free(message->subj);
     message->subj = NULL;
 #endif
-    g_list_foreach(message->references, (GFunc) g_free, NULL);
-    g_list_free(message->references);
+    g_list_free_full(message->references, g_free);
     message->references = NULL;
 
-    g_list_foreach(message->in_reply_to, (GFunc) g_free, NULL);
-    g_list_free(message->in_reply_to);
+    g_list_free_full(message->in_reply_to, g_free);
     message->in_reply_to = NULL;
 
     g_free(message->message_id);
@@ -164,8 +162,7 @@ libbalsa_message_finalize(GObject * object)
     g_free(message->subtype);
     message->subtype = NULL;
 
-    g_list_foreach(message->parameters, (GFunc) g_strfreev, NULL);
-    g_list_free(message->parameters);
+    g_list_free_full(message->parameters, (GDestroyNotify) g_strfreev);
     message->parameters = NULL;
 
 
diff --git a/libbalsa/message.h b/libbalsa/message.h
index f97aa1fde..a45362dc6 100644
--- a/libbalsa/message.h
+++ b/libbalsa/message.h
@@ -151,8 +151,7 @@ struct _LibBalsaMessageHeaders {
 };
 
 /** FREE_HEADER_LIST() frees user_hdrs */
-#define FREE_HEADER_LIST(l) do{ g_list_foreach((l),(GFunc)g_strfreev,NULL);\
-                                g_list_free(l); } while(0)
+#define FREE_HEADER_LIST(l) do{g_list_free_full((l),(GDestroyNotify)g_strfreev);}while(0)
 
 struct _LibBalsaMessage {
     GObject object;
diff --git a/libbalsa/rfc2445.c b/libbalsa/rfc2445.c
index c2b5b36e7..296ffeaf5 100644
--- a/libbalsa/rfc2445.c
+++ b/libbalsa/rfc2445.c
@@ -146,8 +146,7 @@ libbalsa_vcal_finalize(GObject *self)
        const GObjectClass *parent_class = G_OBJECT_CLASS(libbalsa_vcal_parent_class);
 
     if (vcal->vevent != NULL) {
-       g_list_foreach(vcal->vevent, (GFunc) g_object_unref, NULL);
-       g_list_free(vcal->vevent);
+       g_list_free_full(vcal->vevent, g_object_unref);
     }
 
     (*parent_class->finalize)(self);
@@ -188,8 +187,7 @@ libbalsa_vevent_finalize(GObject *self)
                g_object_unref(vevent->organizer);
        }
        if (vevent->attendee) {
-               g_list_foreach(vevent->attendee, (GFunc) g_object_unref, NULL);
-               g_list_free(vevent->attendee);
+               g_list_free_full(vevent->attendee, g_object_unref);
        }
        g_free(vevent->uid);
        g_free(vevent->summary);
diff --git a/libbalsa/send.c b/libbalsa/send.c
index f7667522e..b206157c9 100644
--- a/libbalsa/send.c
+++ b/libbalsa/send.c
@@ -1831,8 +1831,7 @@ libbalsa_create_rfc2440_buffer(LibBalsaMessage *message,
                                               always_trust,
                                               parent, error);
         }
-        g_list_foreach(encrypt_for, (GFunc) g_free, NULL);
-        g_list_free(encrypt_for);
+        g_list_free_full(encrypt_for, g_free);
         if (!result) {
             return LIBBALSA_MESSAGE_ENCRYPT_ERROR;
         }
diff --git a/src/balsa-app.c b/src/balsa-app.c
index fa12a159a..35d4418f5 100644
--- a/src/balsa-app.c
+++ b/src/balsa-app.c
@@ -439,8 +439,7 @@ balsa_app_destroy(void)
 {
     config_save();
 
-    g_list_foreach(balsa_app.address_book_list, (GFunc)g_object_unref, NULL);
-    g_list_free(balsa_app.address_book_list);
+    g_list_free_full(balsa_app.address_book_list, g_object_unref);
     balsa_app.address_book_list = NULL;
 
     /* now free filters */
@@ -449,21 +448,17 @@ balsa_app_destroy(void)
     g_slist_free(balsa_app.filters);
     balsa_app.filters = NULL;
 
-    g_list_foreach(balsa_app.identities, (GFunc)g_object_unref, NULL);
-    g_list_free(balsa_app.identities);
+    g_list_free_full(balsa_app.identities, g_object_unref);
     balsa_app.identities = NULL;
 
-    g_list_foreach(balsa_app.inbox_input, (GFunc)g_object_unref, NULL);
-    g_list_free(balsa_app.inbox_input);
+    g_list_free_full(balsa_app.inbox_input, g_object_unref);
     balsa_app.inbox_input = NULL;
 
 
-    g_list_foreach(balsa_app.folder_mru, (GFunc)g_free, NULL);
-    g_list_free(balsa_app.folder_mru);
+    g_list_free_full(balsa_app.folder_mru, g_free);
     balsa_app.folder_mru = NULL;
 
-    g_list_foreach(balsa_app.fcc_mru, (GFunc)g_free, NULL);
-    g_list_free(balsa_app.fcc_mru);
+    g_list_free_full(balsa_app.fcc_mru, g_free);
     balsa_app.fcc_mru = NULL;
 
 
diff --git a/src/balsa-index.c b/src/balsa-index.c
index ee52f5dae..04249ee78 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -1478,8 +1478,7 @@ bndx_store_address(gpointer data)
     GList *messages = balsa_index_selected_list(BALSA_INDEX(data));
 
     balsa_store_address_from_messages(messages);
-    g_list_foreach(messages, (GFunc)g_object_unref, NULL);
-    g_list_free(messages);
+    g_list_free_full(messages, g_object_unref);
 }
 
 static void
diff --git a/src/balsa-mblist.c b/src/balsa-mblist.c
index dd340edff..5270bf717 100644
--- a/src/balsa-mblist.c
+++ b/src/balsa-mblist.c
@@ -2056,8 +2056,7 @@ bmbl_mru_combo_box_setup(GtkComboBox * combo_box)
     gtk_combo_box_set_active(combo_box, -1);
     store = GTK_LIST_STORE(gtk_combo_box_get_model(combo_box));
     gtk_list_store_clear(store);
-    g_slist_foreach(mro->real_urls, (GFunc) g_free, NULL);
-    g_slist_free(mro->real_urls);
+    g_slist_free_full(mro->real_urls, g_free);
     mro->real_urls = NULL;
 
     for (list = *mro->url_list; list; list = list->next) {
@@ -2114,8 +2113,7 @@ bmbl_mru_combo_box_changed(GtkComboBox * combo_box,
 static void
 bmbl_mru_combo_box_destroy_cb(BalsaMBListMRUOption * mro)
 {
-    g_slist_foreach(mro->real_urls, (GFunc) g_free, NULL);
-    g_slist_free(mro->real_urls);
+    g_slist_free_full(mro->real_urls, g_free);
     g_free(mro);
 }
 
diff --git a/src/balsa-mime-widget-text.c b/src/balsa-mime-widget-text.c
index 528d37b3e..fd2f6251d 100644
--- a/src/balsa-mime-widget-text.c
+++ b/src/balsa-mime-widget-text.c
@@ -909,8 +909,7 @@ static void
 destroy_cite_bars(GList * cite_bars)
 {
     /* note: the widgets are destroyed by the text view */
-    g_list_foreach(cite_bars, (GFunc) g_free, NULL);
-    g_list_free(cite_bars);
+    g_list_free_full(cite_bars, g_free);
 }
 
 typedef struct {
diff --git a/src/balsa-print-object-text.c b/src/balsa-print-object-text.c
index 9a1373959..37fb79b5f 100644
--- a/src/balsa-print-object-text.c
+++ b/src/balsa-print-object-text.c
@@ -119,8 +119,7 @@ balsa_print_object_text_destroy(GObject * self)
 {
     BalsaPrintObjectText *po = BALSA_PRINT_OBJECT_TEXT(self);
 
-    g_list_foreach(po->attributes, (GFunc) g_free, NULL);
-    g_list_free(po->attributes);
+    g_list_free_full(po->attributes, g_free);
     g_free(po->text);
 
     G_OBJECT_CLASS(parent_class)->finalize(self);
@@ -309,8 +308,7 @@ balsa_print_object_text_plain(GList *list, GtkPrintContext * context,
            this_par_part = g_list_next(this_par_part);
        }
        if (attr_list) {
-           g_list_foreach(attr_list, (GFunc) g_free, NULL);
-           g_list_free(attr_list);
+           g_list_free_full(attr_list, g_free);
        }
        g_list_free(par_parts);
        g_array_free(attr_offs, TRUE);
diff --git a/src/filter-edit-callbacks.c b/src/filter-edit-callbacks.c
index 8ecafd4b2..b16593e5e 100644
--- a/src/filter-edit-callbacks.c
+++ b/src/filter-edit-callbacks.c
@@ -1336,8 +1336,7 @@ update_filters_mailbox(GtkTreeModel * model, GtkTreePath * path,
        return FALSE;
 
     /* First we free the filters list (which is now obsolete) */
-    g_slist_foreach(mailbox->filters, (GFunc) g_free, NULL);
-    g_slist_free(mailbox->filters);
+    g_slist_free_full(mailbox->filters, g_free);
     mailbox->filters = NULL;
     /* Second we replace old filters name by the new ones
      * Note : deleted filters are also removed */
@@ -1439,8 +1438,7 @@ void fe_destroy_window_cb(GtkWidget * widget,gpointer throwaway)
     new_filters_names=NULL;
 
     /* free all strings in fe_user_headers_list */
-    g_list_foreach(fe_user_headers_list,(GFunc)g_free,NULL);
-    g_list_free(fe_user_headers_list);
+    g_list_free_full(fe_user_headers_list, g_free);
     fe_user_headers_list = NULL;
 
     fe_already_open=FALSE;
diff --git a/src/filter-run-callbacks.c b/src/filter-run-callbacks.c
index e75a6eb13..1e85469c7 100644
--- a/src/filter-run-callbacks.c
+++ b/src/filter-run-callbacks.c
@@ -146,8 +146,7 @@ static
 void save_filters(BalsaFilterRunDialog * p)
 {
     if (p->filters_modified) {
-       g_slist_foreach(p->mbox->filters, (GFunc) g_free, NULL);
-       g_slist_free(p->mbox->filters);
+       g_slist_free_full(p->mbox->filters, g_free);
        p->mbox->filters=build_selected_filters_list(p->selected_filters,FALSE);
        config_mailbox_filters_save(p->mbox);
        p->filters_modified=FALSE;
diff --git a/src/main-window.c b/src/main-window.c
index ee38f9d91..f2ddfd8ba 100644
--- a/src/main-window.c
+++ b/src/main-window.c
@@ -3464,8 +3464,7 @@ bw_check_messages_thread(struct check_messages_thread_info *info)
                libbalsa_progress_dialog_ensure(&progress_dialog, _("Checking Mail…"), 
GTK_WINDOW(info->window), _("Mailboxes"));
        }
        g_slist_foreach(list, (GFunc) bw_mailbox_check, info);
-       g_slist_foreach(list, (GFunc) g_object_unref, NULL);
-       g_slist_free(list);
+       g_slist_free_full(list, g_object_unref);
        if (info->with_progress_dialog) {
                libbalsa_progress_dialog_update(&progress_dialog, _("Mailboxes"), TRUE, 1.0, NULL);
        }
diff --git a/src/print-gtk.c b/src/print-gtk.c
index a96fa875b..3bb22ddc7 100644
--- a/src/print-gtk.c
+++ b/src/print-gtk.c
@@ -785,8 +785,7 @@ message_print(LibBalsaMessage * msg, GtkWindow * parent)
     /* clean up */
     if (err)
        g_error_free(err);
-    g_list_foreach(print_data->print_parts, (GFunc) g_object_unref, NULL);
-    g_list_free(print_data->print_parts);
+    g_list_free_full(print_data->print_parts, g_object_unref);
     g_free(print_data->footer);
     g_free(print_data);
     g_object_unref(G_OBJECT(print));
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index b62ee4e8b..dc2618cfc 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -632,8 +632,7 @@ balsa_sendmsg_destroy_handler(BalsaSendmsg * bsmsg)
     g_free(bsmsg->fcc_url);
     g_free(bsmsg->in_reply_to);
     if(bsmsg->references) {
-        g_list_foreach(bsmsg->references, (GFunc) g_free, NULL);
-        g_list_free(bsmsg->references);
+        g_list_free_full(bsmsg->references, g_free);
         bsmsg->references = NULL;
     }
 
@@ -2075,8 +2074,7 @@ insert_selected_messages(BalsaSendmsg *bsmsg, QuoteType type)
             gtk_text_buffer_insert_at_cursor(buffer, body->str, body->len);
             g_string_free(body, TRUE);
        }
-       g_list_foreach(l, (GFunc)g_object_unref, NULL);
-        g_list_free(l);
+       g_list_free_full(l, g_object_unref);
     }
 }
 
@@ -2114,8 +2112,7 @@ sw_attach_messages_activated(GSimpleAction * action,
                 break;
             }
        }
-       g_list_foreach(l, (GFunc)g_object_unref, NULL);
-        g_list_free(l);
+       g_list_free_full(l, g_object_unref);
     }
 }
 
@@ -2810,8 +2807,7 @@ drag_data_quote(GtkWidget * widget,
             if (!find_file.found)
                 add_attachment(bsmsg, uri_list->data, FALSE, NULL);
         }
-        g_slist_foreach(uri_list, (GFunc) g_free, NULL);
-        g_slist_free(uri_list);
+        g_slist_free_full(uri_list, g_free);
     }
         break;
     case TARGET_EMAIL:
@@ -7093,8 +7089,7 @@ sendmsg_window_reply_embedded(LibBalsaMessageBody *part,
                              in_reply_to, message_id);
         fill_body_from_part(bsmsg, part->embhdrs, message_id, references,
                             part->parts, QUOTE_ALL);
-        g_list_foreach(references, (GFunc) g_free, NULL);
-        g_list_free(references);
+        g_list_free_full(references, g_free);
     }
 
     if (reply_type == SEND_REPLY_ALL)
diff --git a/src/store-address.c b/src/store-address.c
index aa4babe96..0f4a4e706 100644
--- a/src/store-address.c
+++ b/src/store-address.c
@@ -178,8 +178,7 @@ store_address_response(GtkWidget * dialog, gint response,
         g_object_weak_unref(G_OBJECT(list->data),
                             (GWeakNotify) store_address_weak_notify, info);
     }
-    g_list_foreach(info->entries_list, (GFunc) g_free, NULL);
-    g_list_free(info->entries_list);
+    g_list_free_full(info->entries_list, g_free);
     store_address_free(info);
 }
 


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