Release counter and session watches whe unregistering
authorSamuel Ortiz <sameo@linux.intel.com>
Fri, 8 Oct 2010 21:36:44 +0000 (23:36 +0200)
committerSamuel Ortiz <sameo@linux.intel.com>
Fri, 8 Oct 2010 21:36:44 +0000 (23:36 +0200)
Releasing the watches from the hash table freeing routines lead to double
freeing the interface data watch pointer in case the owner would disappear
before unregistering.

src/counter.c
src/session.c

index 6a0a994..4fc4748 100644 (file)
@@ -45,9 +45,6 @@ static void remove_counter(gpointer user_data)
 
        DBG("owner %s path %s", counter->owner, counter->path);
 
-       if (counter->watch > 0)
-               g_dbus_remove_watch(connection, counter->watch);
-
        __connman_rtnl_update_interval_remove(counter->interval);
 
        __connman_service_counter_unregister(counter->path);
@@ -119,6 +116,9 @@ int __connman_counter_unregister(const char *owner, const char *path)
        if (g_strcmp0(owner, counter->owner) != 0)
                return -EACCES;
 
+       if (counter->watch > 0)
+               g_dbus_remove_watch(connection, counter->watch);
+
        g_hash_table_remove(owner_mapping, counter->owner);
        g_hash_table_remove(counter_table, counter->path);
 
@@ -150,6 +150,9 @@ static void release_counter(gpointer key, gpointer value, gpointer user_data)
 
        DBG("owner %s path %s", counter->owner, counter->path);
 
+       if (counter->watch > 0)
+               g_dbus_remove_watch(connection, counter->watch);
+
        message = dbus_message_new_method_call(counter->owner, counter->path,
                                        CONNMAN_COUNTER_INTERFACE, "Release");
        if (message == NULL)
index 3d3c92d..9264c0c 100644 (file)
@@ -104,9 +104,6 @@ static void remove_session(gpointer user_data)
 {
        struct connman_session *session = user_data;
 
-       if (session->watch > 0)
-               g_dbus_remove_watch(connection, session->watch);
-
        session->bearer = NULL;
        if (session->service)
                connman_service_unref(session->service);
@@ -152,6 +149,9 @@ static int session_disconnect(struct connman_session *session)
                g_hash_table_remove(bearer_hash, bearer);
        }
 
+       if (session->watch > 0)
+               g_dbus_remove_watch(connection, session->watch);
+
        g_hash_table_remove(session_hash, session);
 
        return 0;