core: cleanup freeing of glib collections of pointers

When freeing one of the collections such as GArray, GPtrArray, GSList,
etc. it is common that the items inside the connections must be
freed/unrefed too.

The previous code often iterated over the collection first with
e.g. g_ptr_array_foreach and passing e.g. g_free as GFunc argument.
For one, this has the problem, that g_free has a different signature
GDestroyNotify then the expected GFunc. Moreover, this can be
simplified either by setting a clear function
(g_ptr_array_set_clear_func) or by passing the destroy function to the
free function (g_slist_free_full).

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller
2013-10-18 16:07:26 +02:00
parent 1c93b24829
commit 3eb1d5e902
26 changed files with 69 additions and 108 deletions

View File

@@ -389,7 +389,7 @@ nmc_connection_detail (NMConnection *connection, NmCli *nmc)
}
static void
fill_output_connection (NMConnection *data, gpointer user_data)
fill_output_connection (gpointer data, gpointer user_data)
{
NMConnection *connection = (NMConnection *) data;
NmCli *nmc = (NmCli *) user_data;
@@ -502,7 +502,7 @@ do_connections_show (NmCli *nmc, int argc, char **argv)
g_ptr_array_add (nmc->output_data, arr);
/* Add values */
g_slist_foreach (nmc->system_connections, (GFunc) fill_output_connection, nmc);
g_slist_foreach (nmc->system_connections, fill_output_connection, nmc);
print_data (nmc); /* Print all data */
} else {
g_clear_error (&error1); /* the error1 is only relevant for 'show configured' without arguments */