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:
@@ -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 */
|
||||
|
Reference in New Issue
Block a user