From 9065f247c32c3501651e62aa1b4b4ef4bf0ec7ae Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 14 Sep 2012 15:33:42 -0500 Subject: [PATCH] vpn: reduce memory usage a bit No need to copy the list when (a) we never care if it gets modified in-place (since the loops break when the connection is found) and (b) we never modify it in place anyway. Reduces the possibility of leaking the list due to programming errors too. --- src/vpn-manager/nm-vpn-manager.c | 6 ++---- src/vpn-manager/nm-vpn-service.c | 4 ++-- src/vpn-manager/nm-vpn-service.h | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/vpn-manager/nm-vpn-manager.c b/src/vpn-manager/nm-vpn-manager.c index ebf85e30eb..7743fddd7c 100644 --- a/src/vpn-manager/nm-vpn-manager.c +++ b/src/vpn-manager/nm-vpn-manager.c @@ -82,7 +82,7 @@ find_active_vpn_connection_by_connection (NMVPNManager *self, NMConnection *conn NMVPNManagerPrivate *priv = NM_VPN_MANAGER_GET_PRIVATE (self); GHashTableIter iter; gpointer data; - GSList *active, *aiter; + const GSList *active, *aiter; NMVPNConnection *found = NULL; g_return_val_if_fail (connection, NULL); @@ -99,7 +99,6 @@ find_active_vpn_connection_by_connection (NMVPNManager *self, NMConnection *conn break; } } - g_slist_free (active); } return found; } @@ -174,7 +173,7 @@ nm_vpn_manager_deactivate_connection (NMVPNManager *self, NMVPNManagerPrivate *priv; GHashTableIter iter; gpointer data; - GSList *active, *aiter; + const GSList *active, *aiter; gboolean success = FALSE; g_return_val_if_fail (self, FALSE); @@ -194,7 +193,6 @@ nm_vpn_manager_deactivate_connection (NMVPNManager *self, break; } } - g_slist_free (active); } return success; diff --git a/src/vpn-manager/nm-vpn-service.c b/src/vpn-manager/nm-vpn-service.c index 9b5aec50c2..668cbf2e35 100644 --- a/src/vpn-manager/nm-vpn-service.c +++ b/src/vpn-manager/nm-vpn-service.c @@ -369,12 +369,12 @@ nm_vpn_service_activate (NMVPNService *service, return vpn; } -GSList * +const GSList * nm_vpn_service_get_active_connections (NMVPNService *service) { g_return_val_if_fail (NM_IS_VPN_SERVICE (service), NULL); - return g_slist_copy (NM_VPN_SERVICE_GET_PRIVATE (service)->connections); + return NM_VPN_SERVICE_GET_PRIVATE (service)->connections; } static void diff --git a/src/vpn-manager/nm-vpn-service.h b/src/vpn-manager/nm-vpn-service.h index 6ccdcc4733..e883d55f8b 100644 --- a/src/vpn-manager/nm-vpn-service.h +++ b/src/vpn-manager/nm-vpn-service.h @@ -62,7 +62,7 @@ NMVPNConnection * nm_vpn_service_activate (NMVPNService *service, gulong user_uid, GError **error); -GSList * nm_vpn_service_get_active_connections (NMVPNService *service); +const GSList *nm_vpn_service_get_active_connections (NMVPNService *service); void nm_vpn_service_connections_stop (NMVPNService *service, gboolean fail,