[PATCH BlueZ 2/3] thermometer: Fix D-Bus service disconnect watch removal

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



destroy_watcher() will be automatically called when removing the D-Bus
watch (it was set as the destroy callback when adding the watch),
therefore it is only necessary to remove the watch.
---
 thermometer/thermometer.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/thermometer/thermometer.c b/thermometer/thermometer.c
index a64ed54..9d23275 100644
--- a/thermometer/thermometer.c
+++ b/thermometer/thermometer.c
@@ -136,14 +136,18 @@ static void destroy_watcher(gpointer user_data)
 {
 	struct watcher *watcher = user_data;
 
-	if (watcher->id > 0)
-		g_dbus_remove_watch(watcher->t->conn, watcher->id);
-
 	g_free(watcher->path);
 	g_free(watcher->srv);
 	g_free(watcher);
 }
 
+static void remove_watcher(gpointer user_data)
+{
+	struct watcher *watcher = user_data;
+
+	g_dbus_remove_watch(watcher->t->conn, watcher->id);
+}
+
 static void destroy_char(gpointer user_data)
 {
 	struct characteristic *c = user_data;
@@ -172,7 +176,7 @@ static void destroy_thermometer(gpointer user_data)
 		g_slist_free_full(t->chars, destroy_char);
 
 	if (t->fwatchers != NULL)
-		g_slist_free_full(t->fwatchers, destroy_watcher);
+		g_slist_free_full(t->fwatchers, remove_watcher);
 
 	dbus_connection_unref(t->conn);
 	btd_device_unref(t->dev);
@@ -814,7 +818,7 @@ static void watcher_exit(DBusConnection *conn, void *user_data)
 	remove_int_watcher(t, watcher);
 
 	t->fwatchers = g_slist_remove(t->fwatchers, watcher);
-	watcher->id = 0;
+	g_dbus_remove_watch(watcher->t->conn, watcher->id);
 
 	if (g_slist_length(t->fwatchers) == 0)
 		disable_final_measurement(t);
@@ -893,7 +897,7 @@ static DBusMessage *unregister_watcher(DBusConnection *conn, DBusMessage *msg,
 	remove_int_watcher(t, watcher);
 
 	t->fwatchers = g_slist_remove(t->fwatchers, watcher);
-	destroy_watcher(watcher);
+	g_dbus_remove_watch(watcher->t->conn, watcher->id);
 
 	if (g_slist_length(t->fwatchers) == 0)
 		disable_final_measurement(t);
-- 
1.7.5.4

--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux