vpn: fix memory leaks

Two problems here:

1) code	that called nm_vpn_service_get_active_connections() wasn't freeing
the returned list, leaking it

2) No real reason to reference each item in the returned list in
nm_vpn_manager_get_active_connections(), it just makes it easier to
forget to unref things later
This commit is contained in:
Dan Williams 2011-03-24 14:12:06 -05:00
parent 1862ab329f
commit 7da9e2f607
2 changed files with 27 additions and 22 deletions

View file

@ -471,7 +471,6 @@ update_ip4_routing_and_dns (NMPolicy *policy, gboolean force_update)
dns_type = NM_DNS_IP_CONFIG_TYPE_VPN;
}
g_object_unref (candidate);
}
g_slist_free (vpns);
@ -596,7 +595,6 @@ update_ip6_routing_and_dns (NMPolicy *policy, gboolean force_update)
dns_type = NM_DNS_IP_CONFIG_TYPE_VPN;
}
g_object_unref (candidate);
}
g_slist_free (vpns);
#endif

View file

@ -115,22 +115,26 @@ find_active_vpn_connection_by_connection (NMVPNManager *self, NMConnection *conn
NMVPNManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE (self);
GHashTableIter iter;
gpointer data;
GSList *connections, *elt;
GSList *active, *aiter;
NMVPNConnection *found = NULL;
g_return_val_if_fail (connection, NULL);
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
g_hash_table_iter_init (&iter, priv->services);
while (g_hash_table_iter_next (&iter, NULL, &data)) {
connections = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (data));
for (elt = connections; elt; elt = g_slist_next (elt)) {
NMVPNConnection *vpn = NM_VPN_CONNECTION (elt->data);
while (g_hash_table_iter_next (&iter, NULL, &data) && (found == NULL)) {
active = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (data));
for (aiter = active; aiter; aiter = g_slist_next (aiter)) {
NMVPNConnection *vpn = NM_VPN_CONNECTION (aiter->data);
if (nm_vpn_connection_get_connection (vpn) == connection)
return vpn;
if (nm_vpn_connection_get_connection (vpn) == connection) {
found = vpn;
break;
}
}
g_slist_free (active);
}
return NULL;
return found;
}
static void
@ -225,7 +229,8 @@ nm_vpn_manager_deactivate_connection (NMVPNManager *self,
NMVPNManagerPrivate *priv;
GHashTableIter iter;
gpointer data;
GSList *active, *elt;
GSList *active, *aiter;
gboolean success = FALSE;
g_return_val_if_fail (self, FALSE);
g_return_val_if_fail (NM_IS_VPN_MANAGER (self), FALSE);
@ -233,21 +238,23 @@ nm_vpn_manager_deactivate_connection (NMVPNManager *self,
priv = NM_VPN_MANAGER_GET_PRIVATE (self);
g_hash_table_iter_init (&iter, priv->services);
while (g_hash_table_iter_next (&iter, NULL, &data)) {
while (g_hash_table_iter_next (&iter, NULL, &data) && (success == FALSE)) {
active = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (data));
for (elt = active; elt; elt = g_slist_next (elt)) {
NMVPNConnection *vpn = NM_VPN_CONNECTION (elt->data);
for (aiter = active; aiter; aiter = g_slist_next (aiter)) {
NMVPNConnection *vpn = NM_VPN_CONNECTION (aiter->data);
const char *vpn_path;
vpn_path = nm_vpn_connection_get_active_connection_path (vpn);
if (!strcmp (path, vpn_path)) {
nm_vpn_connection_disconnect (vpn, reason);
return TRUE;
success = TRUE;
break;
}
}
g_slist_free (active);
}
return FALSE;
return success;
}
void
@ -258,7 +265,7 @@ nm_vpn_manager_add_active_connections (NMVPNManager *self,
NMVPNManagerPrivate *priv;
GHashTableIter iter;
gpointer data;
GSList *active, *elt;
GSList *active, *aiter;
g_return_if_fail (self);
g_return_if_fail (NM_IS_VPN_MANAGER (self));
@ -268,8 +275,8 @@ nm_vpn_manager_add_active_connections (NMVPNManager *self,
g_hash_table_iter_init (&iter, priv->services);
while (g_hash_table_iter_next (&iter, NULL, &data)) {
active = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (data));
for (elt = active; elt; elt = g_slist_next (elt)) {
NMVPNConnection *vpn = NM_VPN_CONNECTION (elt->data);
for (aiter = active; aiter; aiter = g_slist_next (aiter)) {
NMVPNConnection *vpn = NM_VPN_CONNECTION (aiter->data);
const char *path;
if (!filter || (nm_vpn_connection_get_connection (vpn) == filter)) {
@ -277,6 +284,7 @@ nm_vpn_manager_add_active_connections (NMVPNManager *self,
g_ptr_array_add (array, g_strdup (path));
}
}
g_slist_free (active);
}
}
@ -286,7 +294,7 @@ nm_vpn_manager_get_active_connections (NMVPNManager *self)
NMVPNManagerPrivate *priv;
GHashTableIter iter;
gpointer data;
GSList *list = NULL, *active, *elt;
GSList *list = NULL, *active;
g_return_val_if_fail (self, NULL);
g_return_val_if_fail (NM_IS_VPN_MANAGER (self), NULL);
@ -295,8 +303,7 @@ nm_vpn_manager_get_active_connections (NMVPNManager *self)
g_hash_table_iter_init (&iter, priv->services);
while (g_hash_table_iter_next (&iter, NULL, &data)) {
active = nm_vpn_service_get_active_connections (NM_VPN_SERVICE (data));
for (elt = active; elt; elt = g_slist_next (elt))
list = g_slist_append (list, g_object_ref (G_OBJECT (elt->data)));
list = g_slist_concat (list, active);
}
return list;
}