session: Move cleanup/destroy function up
authorDaniel Wagner <daniel.wagner@bmw-carit.de>
Wed, 5 Dec 2012 13:57:48 +0000 (14:57 +0100)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Wed, 5 Dec 2012 14:50:59 +0000 (16:50 +0200)
We need to call those function from create_policy_config() therefore
more it in front of it.

src/session.c

index fa6a0e9..076eb80 100644 (file)
@@ -236,6 +236,54 @@ static char *service2bearer(enum connman_service_type type)
        return "";
 }
 
+static void destroy_policy_config(struct connman_session *session)
+{
+       if (session->policy == NULL) {
+               g_free(session->policy_config);
+               return;
+       }
+
+       (*session->policy->destroy)(session);
+}
+
+static void free_session(struct connman_session *session)
+{
+       if (session == NULL)
+               return;
+
+       if (session->notify_watch > 0)
+               g_dbus_remove_watch(connection, session->notify_watch);
+
+       destroy_policy_config(session);
+       g_slist_free(session->info->config.allowed_bearers);
+       g_free(session->owner);
+       g_free(session->session_path);
+       g_free(session->notify_path);
+       g_free(session->info);
+       g_free(session->info_last);
+
+       g_free(session);
+}
+
+static void cleanup_session(gpointer user_data)
+{
+       struct connman_session *session = user_data;
+       struct session_info *info = session->info;
+
+       DBG("remove %s", session->session_path);
+
+       g_slist_free(session->user_allowed_bearers);
+       g_hash_table_destroy(session->service_hash);
+       g_sequence_free(session->service_list);
+
+       if (info->entry != NULL &&
+                       info->entry->reason == CONNMAN_SESSION_REASON_CONNECT) {
+               __connman_service_disconnect(info->entry->service);
+       }
+
+       free_session(session);
+}
+
 static int assign_policy_plugin(struct connman_session *session)
 {
        if (session->policy != NULL)
@@ -268,16 +316,6 @@ static int create_policy_config(struct connman_session *session,
        return (*session->policy->create)(session, callback, user_data);
 }
 
-static void destroy_policy_config(struct connman_session *session)
-{
-       if (session->policy == NULL) {
-               g_free(session->policy_config);
-               return;
-       }
-
-       (*session->policy->destroy)(session);
-}
-
 static void probe_policy(struct connman_session_policy *policy)
 {
 
@@ -860,44 +898,6 @@ static gint sort_services(gconstpointer a, gconstpointer b, gpointer user_data)
                                session);
 }
 
-static void free_session(struct connman_session *session)
-{
-       if (session == NULL)
-               return;
-
-       if (session->notify_watch > 0)
-               g_dbus_remove_watch(connection, session->notify_watch);
-
-       destroy_policy_config(session);
-       g_slist_free(session->info->config.allowed_bearers);
-       g_free(session->owner);
-       g_free(session->session_path);
-       g_free(session->notify_path);
-       g_free(session->info);
-       g_free(session->info_last);
-
-       g_free(session);
-}
-
-static void cleanup_session(gpointer user_data)
-{
-       struct connman_session *session = user_data;
-       struct session_info *info = session->info;
-
-       DBG("remove %s", session->session_path);
-
-       g_slist_free(session->user_allowed_bearers);
-       g_hash_table_destroy(session->service_hash);
-       g_sequence_free(session->service_list);
-
-       if (info->entry != NULL &&
-                       info->entry->reason == CONNMAN_SESSION_REASON_CONNECT) {
-               __connman_service_disconnect(info->entry->service);
-       }
-
-       free_session(session);
-}
-
 static enum connman_session_state service_to_session_state(enum connman_service_state state)
 {
        switch (state) {