summaryrefslogtreecommitdiff
path: root/libnm-glib
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2013-10-18 16:07:26 +0200
committerThomas Haller <thaller@redhat.com>2013-10-22 19:53:57 +0200
commit3eb1d5e9024108fe656476dc5a11fefd194d0c54 (patch)
treee59c0a5cef44de57babcf79784320092691a467e /libnm-glib
parent1c93b24829d61e58624bf2dd20ebb34b3fceabea (diff)
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>
Diffstat (limited to 'libnm-glib')
-rw-r--r--libnm-glib/libnm_glib.c3
-rw-r--r--libnm-glib/nm-active-connection.c2
-rw-r--r--libnm-glib/nm-client.c3
-rw-r--r--libnm-glib/nm-device-bond.c2
-rw-r--r--libnm-glib/nm-device-bridge.c2
-rw-r--r--libnm-glib/nm-device-team.c2
-rw-r--r--libnm-glib/nm-ip4-config.c17
-rw-r--r--libnm-glib/nm-ip6-config.c21
-rw-r--r--libnm-glib/nm-object.c9
-rw-r--r--libnm-glib/nm-types.c3
10 files changed, 23 insertions, 41 deletions
diff --git a/libnm-glib/libnm_glib.c b/libnm-glib/libnm_glib.c
index 1d75578612..2abd6ab881 100644
--- a/libnm-glib/libnm_glib.c
+++ b/libnm-glib/libnm_glib.c
@@ -456,8 +456,7 @@ _libnm_glib_ctx_free (libnm_glib_ctx *ctx)
if (ctx->callbacks_lock)
g_mutex_free (ctx->callbacks_lock);
- g_slist_foreach (ctx->callbacks, (GFunc)g_free, NULL);
- g_slist_free (ctx->callbacks);
+ g_slist_free_full (ctx->callbacks, g_free);
if (ctx->thread)
g_thread_join (ctx->thread);
diff --git a/libnm-glib/nm-active-connection.c b/libnm-glib/nm-active-connection.c
index 6b3c782154..c4744837bd 100644
--- a/libnm-glib/nm-active-connection.c
+++ b/libnm-glib/nm-active-connection.c
@@ -354,7 +354,7 @@ dispose (GObject *object)
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE (object);
if (priv->devices) {
- g_ptr_array_foreach (priv->devices, (GFunc) g_object_unref, NULL);
+ g_ptr_array_set_free_func (priv->devices, g_object_unref);
g_ptr_array_free (priv->devices, TRUE);
priv->devices = NULL;
}
diff --git a/libnm-glib/nm-client.c b/libnm-glib/nm-client.c
index 15c708acc1..c424037bc0 100644
--- a/libnm-glib/nm-client.c
+++ b/libnm-glib/nm-client.c
@@ -2034,8 +2034,7 @@ dispose (GObject *object)
g_clear_object (&priv->primary_connection);
g_clear_object (&priv->activating_connection);
- g_slist_foreach (priv->pending_activations, (GFunc) activate_info_free, NULL);
- g_slist_free (priv->pending_activations);
+ g_slist_free_full (priv->pending_activations, (GDestroyNotify) activate_info_free);
priv->pending_activations = NULL;
g_hash_table_destroy (priv->permissions);
diff --git a/libnm-glib/nm-device-bond.c b/libnm-glib/nm-device-bond.c
index 04188a43bf..18c10484d0 100644
--- a/libnm-glib/nm-device-bond.c
+++ b/libnm-glib/nm-device-bond.c
@@ -238,7 +238,7 @@ dispose (GObject *object)
g_clear_object (&priv->proxy);
if (priv->slaves) {
- g_ptr_array_foreach (priv->slaves, (GFunc) g_object_unref, NULL);
+ g_ptr_array_set_free_func (priv->slaves, g_object_unref);
g_ptr_array_free (priv->slaves, TRUE);
priv->slaves = NULL;
}
diff --git a/libnm-glib/nm-device-bridge.c b/libnm-glib/nm-device-bridge.c
index e632a9b2ea..2bec00fbfb 100644
--- a/libnm-glib/nm-device-bridge.c
+++ b/libnm-glib/nm-device-bridge.c
@@ -246,7 +246,7 @@ dispose (GObject *object)
g_clear_object (&priv->proxy);
if (priv->slaves) {
- g_ptr_array_foreach (priv->slaves, (GFunc) g_object_unref, NULL);
+ g_ptr_array_set_free_func (priv->slaves, g_object_unref);
g_ptr_array_free (priv->slaves, TRUE);
priv->slaves = NULL;
}
diff --git a/libnm-glib/nm-device-team.c b/libnm-glib/nm-device-team.c
index 67f0d1d44f..adf0113724 100644
--- a/libnm-glib/nm-device-team.c
+++ b/libnm-glib/nm-device-team.c
@@ -234,7 +234,7 @@ dispose (GObject *object)
g_clear_object (&priv->proxy);
if (priv->slaves) {
- g_ptr_array_foreach (priv->slaves, (GFunc) g_object_unref, NULL);
+ g_ptr_array_set_free_func (priv->slaves, g_object_unref);
g_ptr_array_free (priv->slaves, TRUE);
priv->slaves = NULL;
}
diff --git a/libnm-glib/nm-ip4-config.c b/libnm-glib/nm-ip4-config.c
index 0fc3a1fd86..ec523a0333 100644
--- a/libnm-glib/nm-ip4-config.c
+++ b/libnm-glib/nm-ip4-config.c
@@ -69,8 +69,7 @@ demarshal_ip4_address_array (NMObject *object, GParamSpec *pspec, GValue *value,
{
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
- g_slist_foreach (priv->addresses, (GFunc) nm_ip4_address_unref, NULL);
- g_slist_free (priv->addresses);
+ g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
priv->addresses = NULL;
priv->addresses = nm_utils_ip4_addresses_from_gvalue (value);
@@ -108,8 +107,7 @@ demarshal_ip4_routes_array (NMObject *object, GParamSpec *pspec, GValue *value,
{
NMIP4ConfigPrivate *priv = NM_IP4_CONFIG_GET_PRIVATE (object);
- g_slist_foreach (priv->routes, (GFunc) nm_ip4_route_unref, NULL);
- g_slist_free (priv->routes);
+ g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
priv->routes = NULL;
priv->routes = nm_utils_ip4_routes_from_gvalue (value);
@@ -156,11 +154,8 @@ finalize (GObject *object)
g_free (priv->gateway);
- g_slist_foreach (priv->addresses, (GFunc) nm_ip4_address_unref, NULL);
- g_slist_free (priv->addresses);
-
- g_slist_foreach (priv->routes, (GFunc) nm_ip4_route_unref, NULL);
- g_slist_free (priv->routes);
+ g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip4_address_unref);
+ g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip4_route_unref);
if (priv->nameservers)
g_array_free (priv->nameservers, TRUE);
@@ -169,12 +164,12 @@ finalize (GObject *object)
g_array_free (priv->wins, TRUE);
if (priv->domains) {
- g_ptr_array_foreach (priv->domains, (GFunc) g_free, NULL);
+ g_ptr_array_set_free_func (priv->domains, g_free);
g_ptr_array_free (priv->domains, TRUE);
}
if (priv->searches) {
- g_ptr_array_foreach (priv->searches, (GFunc) g_free, NULL);
+ g_ptr_array_set_free_func (priv->searches, g_free);
g_ptr_array_free (priv->searches, TRUE);
}
diff --git a/libnm-glib/nm-ip6-config.c b/libnm-glib/nm-ip6-config.c
index cd717c095c..01e2cae5f8 100644
--- a/libnm-glib/nm-ip6-config.c
+++ b/libnm-glib/nm-ip6-config.c
@@ -80,8 +80,7 @@ demarshal_ip6_address_array (NMObject *object, GParamSpec *pspec, GValue *value,
{
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
- g_slist_foreach (priv->addresses, (GFunc) nm_ip6_address_unref, NULL);
- g_slist_free (priv->addresses);
+ g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip6_address_unref);
priv->addresses = NULL;
priv->addresses = nm_utils_ip6_addresses_from_gvalue (value);
@@ -127,8 +126,7 @@ demarshal_ip6_routes_array (NMObject *object, GParamSpec *pspec, GValue *value,
{
NMIP6ConfigPrivate *priv = NM_IP6_CONFIG_GET_PRIVATE (object);
- g_slist_foreach (priv->routes, (GFunc) nm_ip6_route_unref, NULL);
- g_slist_free (priv->routes);
+ g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
priv->routes = NULL;
priv->routes = nm_utils_ip6_routes_from_gvalue (value);
@@ -289,22 +287,17 @@ finalize (GObject *object)
g_free (priv->gateway);
- g_slist_foreach (priv->addresses, (GFunc) nm_ip6_address_unref, NULL);
- g_slist_free (priv->addresses);
-
- g_slist_foreach (priv->routes, (GFunc) nm_ip6_route_unref, NULL);
- g_slist_free (priv->routes);
-
- g_slist_foreach (priv->nameservers, (GFunc) g_free, NULL);
- g_slist_free (priv->nameservers);
+ g_slist_free_full (priv->addresses, (GDestroyNotify) nm_ip6_address_unref);
+ g_slist_free_full (priv->routes, (GDestroyNotify) nm_ip6_route_unref);
+ g_slist_free_full (priv->nameservers, g_free);
if (priv->domains) {
- g_ptr_array_foreach (priv->domains, (GFunc) g_free, NULL);
+ g_ptr_array_set_free_func (priv->domains, g_free);
g_ptr_array_free (priv->domains, TRUE);
}
if (priv->searches) {
- g_ptr_array_foreach (priv->searches, (GFunc) g_free, NULL);
+ g_ptr_array_set_free_func (priv->searches, g_free);
g_ptr_array_free (priv->searches, TRUE);
}
diff --git a/libnm-glib/nm-object.c b/libnm-glib/nm-object.c
index 6424e29cff..e58b020501 100644
--- a/libnm-glib/nm-object.c
+++ b/libnm-glib/nm-object.c
@@ -317,12 +317,10 @@ dispose (GObject *object)
priv->notify_id = 0;
}
- g_slist_foreach (priv->notify_props, (GFunc) g_free, NULL);
- g_slist_free (priv->notify_props);
+ g_slist_free_full (priv->notify_props, g_free);
priv->notify_props = NULL;
- g_slist_foreach (priv->property_interfaces, (GFunc) g_free, NULL);
- g_slist_free (priv->property_interfaces);
+ g_slist_free_full (priv->property_interfaces, g_free);
priv->property_interfaces = NULL;
g_clear_object (&priv->properties_proxy);
@@ -341,8 +339,7 @@ finalize (GObject *object)
{
NMObjectPrivate *priv = NM_OBJECT_GET_PRIVATE (object);
- g_slist_foreach (priv->property_tables, (GFunc) g_hash_table_destroy, NULL);
- g_slist_free (priv->property_tables);
+ g_slist_free_full (priv->property_tables, (GDestroyNotify) g_hash_table_destroy);
g_free (priv->path);
if (priv->pseudo_properties)
diff --git a/libnm-glib/nm-types.c b/libnm-glib/nm-types.c
index 098af8d8ec..f9ba6d240b 100644
--- a/libnm-glib/nm-types.c
+++ b/libnm-glib/nm-types.c
@@ -363,8 +363,7 @@ _nm_ip6_address_array_demarshal (GValue *value, GSList **dest)
return FALSE;
if (*dest) {
- g_slist_foreach (*dest, (GFunc) g_free, NULL);
- g_slist_free (*dest);
+ g_slist_free_full (*dest, g_free);
*dest = NULL;
}