[PATCH] vpn: Do not remove vpn connections hash when vpnd dies

Jukka Rissanen jukka.rissanen at linux.intel.com
Mon Nov 26 02:15:48 PST 2012


We must keep the vpn connections hash alive as long as
connman is running. We must not remove the hash when
vpnd dies, otherwise we might feed null pointer to
various glib hash functions.
---
 plugins/vpn.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/plugins/vpn.c b/plugins/vpn.c
index c7f59a9..f7ffe6b 100644
--- a/plugins/vpn.c
+++ b/plugins/vpn.c
@@ -1456,9 +1456,6 @@ static void vpnd_created(DBusConnection *conn, void *user_data)
 	DBG("connection %p", conn);
 
 	if (starting_vpnd == TRUE) {
-		vpn_connections = g_hash_table_new_full(g_str_hash,
-						g_str_equal,
-						g_free, connection_destroy);
 		get_connections(user_data);
 		starting_vpnd = FALSE;
 	}
@@ -1468,8 +1465,6 @@ static void vpnd_removed(DBusConnection *conn, void *user_data)
 {
 	DBG("connection %p", conn);
 
-	g_hash_table_destroy(vpn_connections);
-	vpn_connections = NULL;
 	starting_vpnd = TRUE;
 }
 
@@ -1773,8 +1768,13 @@ static int vpn_init(void)
 	}
 
 	err = connman_provider_driver_register(&provider_driver);
-	if (err == 0)
+	if (err == 0) {
+		vpn_connections = g_hash_table_new_full(g_str_hash,
+						g_str_equal,
+						g_free, connection_destroy);
+
 		vpnd_created(connection, &provider_driver);
+	}
 
 	return err;
 
@@ -1798,7 +1798,8 @@ static void vpn_exit(void)
 
 	connman_provider_driver_unregister(&provider_driver);
 
-	g_hash_table_destroy(vpn_connections);
+	if (vpn_connections != NULL)
+		g_hash_table_destroy(vpn_connections);
 
 	dbus_connection_unref(connection);
 }
-- 
1.7.11.4




More information about the connman mailing list