diff mbox series

[21/90] connection: Add 'gateway_config_free'.

Message ID 20231206235056.322578-22-gerickson@nuovations.com (mailing list archive)
State Not Applicable, archived
Headers show
Series Add Gateway Low-priority Default Routes for Non-default Services | expand

Commit Message

Grant Erickson Dec. 6, 2023, 11:49 p.m. UTC
From: Grant Erickson <erick205@umn.edu>

Since there are two identical instances of gateway configuration in
gateway data, introduce a function, 'gateway_config_free' to free
those instances rather than copying-and-pasting the logic to free them
twice in 'remove_gateway'.
---
 src/connection.c | 28 ++++++++++++++--------------
 1 file changed, 14 insertions(+), 14 deletions(-)
diff mbox series

Patch

diff --git a/src/connection.c b/src/connection.c
index 72a82dd87f76..5b0f18627f40 100644
--- a/src/connection.c
+++ b/src/connection.c
@@ -1698,27 +1698,27 @@  static void connection_newgateway(int index, const char *gateway)
 	check_default_gateway(data);
 }
 
+static void gateway_config_free(struct gateway_config *config)
+{
+	DBG("config %p", config);
+
+	if (config) {
+		g_free(config->gateway);
+		g_free(config->vpn_ip);
+		g_free(config->vpn_phy_ip);
+		g_free(config);
+	}
+}
+
 static void remove_gateway(gpointer user_data)
 {
 	struct gateway_data *data = user_data;
 
-	DBG("data %p", data);
-
 	GATEWAY_DATA_DBG("data", data);
 
-	if (data->ipv4_config) {
-		g_free(data->ipv4_config->gateway);
-		g_free(data->ipv4_config->vpn_ip);
-		g_free(data->ipv4_config->vpn_phy_ip);
-		g_free(data->ipv4_config);
-	}
+	gateway_config_free(data->ipv4_config);
 
-	if (data->ipv6_config) {
-		g_free(data->ipv6_config->gateway);
-		g_free(data->ipv6_config->vpn_ip);
-		g_free(data->ipv6_config->vpn_phy_ip);
-		g_free(data->ipv6_config);
-	}
+	gateway_config_free(data->ipv6_config);
 
 	connman_service_unref(data->service);