From: Daniel Wagner <[email protected]>

If the config object already exists (the config file exists before the
session is created), just use it.
---
 plugins/session_policy_ivi.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/plugins/session_policy_ivi.c b/plugins/session_policy_ivi.c
index 7632acb..fe4ba74 100644
--- a/plugins/session_policy_ivi.c
+++ b/plugins/session_policy_ivi.c
@@ -124,6 +124,12 @@ static void selinux_context_reply(const unsigned char 
*context, void *user_data)
        DBG("session %p", data->session);
 
        ident = parse_ident(context);
+       if (ident == NULL)
+               goto err;
+
+       policy = g_hash_table_lookup(ident_hash, ident);
+       if (policy != NULL)
+               goto out;
 
        DBG("ident %s", ident);
 
@@ -135,6 +141,9 @@ static void selinux_context_reply(const unsigned char 
*context, void *user_data)
        if (policy->config == NULL)
                goto err;
 
+out:
+       policy->session = data->session;
+
        g_hash_table_replace(session_hash, data->session, policy);
 
        (*data->callback)(data->session, policy->config, data->user_data, 0);
@@ -146,7 +155,8 @@ static void selinux_context_reply(const unsigned char 
*context, void *user_data)
 err:
        (*data->callback)(data->session, NULL, data->user_data, -ENOMEM);
 
-       cleanup_policy(policy);
+       if (policy != NULL && policy->ident == NULL)
+               cleanup_policy(policy);
 
        g_free(data);
        g_free(ident);
@@ -193,8 +203,10 @@ static void policy_ivi_destroy(struct connman_session 
*session)
        policy = g_hash_table_lookup(session_hash, session);
 
        g_hash_table_remove(session_hash, session);
+       policy->session = NULL;
 
-       cleanup_policy(policy);
+       if (policy->ident == NULL)
+               cleanup_policy(policy);
 }
 
 static struct connman_session_policy session_policy_ivi = {
@@ -215,6 +227,12 @@ static struct policy_data *create_policy(const char *ident)
 
        DBG("ident %s", ident);
 
+       policy = g_hash_table_lookup(session_hash, ident);
+       if (policy != NULL) {
+               g_hash_table_replace(ident_hash, g_strdup(ident), policy);
+               return policy;
+       }
+
        policy = g_hash_table_lookup(ident_hash, ident);
        if (policy != NULL)
                return policy;
-- 
1.8.0.rc0

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to