From: Daniel Wagner <daniel.wag...@bmw-carit.de>

We want to make the lifetime of the policy data structure independent
of the policy_hash table.
---
 plugins/session_policy_local.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/plugins/session_policy_local.c b/plugins/session_policy_local.c
index 1e3abfb..8968d14 100644
--- a/plugins/session_policy_local.c
+++ b/plugins/session_policy_local.c
@@ -48,6 +48,7 @@ static DBusConnection *connection;
 
 static GHashTable *policy_hash;
 static GHashTable *session_hash;
+static GSList *policy_list;
 
 struct create_data {
        struct connman_session *session;
@@ -63,7 +64,7 @@ struct policy_data {
        struct connman_session_config *config;
 };
 
-static void cleanup_policy(gpointer user_data)
+static void free_policy(gpointer user_data)
 {
        struct policy_data *policy = user_data;
 
@@ -121,6 +122,8 @@ static struct policy_data *create_policy(const char *ident)
        policy->config = connman_session_create_default_config();
        policy->ident = g_strdup(ident);
 
+       policy_list = g_slist_prepend(policy_list, policy);
+
        g_hash_table_replace(policy_hash, policy->ident, policy);
 
        return policy;
@@ -142,7 +145,11 @@ static void policy_unref(struct policy_data *policy)
        if (__sync_fetch_and_sub(&policy->refcount, 1) != 1)
                return;
 
+       policy_list = g_slist_remove(policy_list, policy);
+
        g_hash_table_remove(policy_hash, policy->ident);
+
+       free_policy(policy);
 };
 
 static void selinux_context_reply(const unsigned char *context, void 
*user_data,
@@ -453,7 +460,7 @@ static int session_policy_local_init(void)
        session_hash = g_hash_table_new_full(g_direct_hash, g_direct_equal,
                                                NULL, NULL);
        policy_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
-                                       NULL, cleanup_policy);
+                                       NULL, NULL);
 
        err = connman_inotify_register(POLICYDIR, notify_handler);
        if (err < 0)
@@ -491,6 +498,8 @@ static void session_policy_local_exit(void)
        g_hash_table_destroy(session_hash);
        g_hash_table_destroy(policy_hash);
 
+       g_slist_free_full(policy_list, free_policy);
+
        connman_session_policy_unregister(&session_policy_local);
 
        dbus_connection_unref(connection);
-- 
1.8.1.3.566.gaa39828

_______________________________________________
connman mailing list
connman@connman.net
http://lists.connman.net/listinfo/connman

Reply via email to