public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ] gdbus: Fix removal of filter after last filter_data
@ 2012-06-23 14:02 Lucas De Marchi
  2012-06-25  8:51 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 11+ messages in thread
From: Lucas De Marchi @ 2012-06-23 14:02 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Lucas De Marchi

If there's a signal watch that's also watching for name
(data->name_watch) currently we are trying to remove the message_filter
twice since we may have the following call chain:

filter_data_remove_callback()
  filter_data_free()
    g_dbus_remove_watch()
      filter_data_remove_callback()
	filter_data_free()
        dbus_connection_remove_filter()
  dbus_connection_remove_filter()

Because of this we can't currently watch for signals passing the bus
name. After this patch we don't have this issue anymore.

We fix this by checking if we are the last filter_data before calling
filter_data_free and thus not calling dbus_connection_remove_filter()
twice.
---
 gdbus/watch.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/gdbus/watch.c b/gdbus/watch.c
index 9a716b0..6fed264 100644
--- a/gdbus/watch.c
+++ b/gdbus/watch.c
@@ -350,6 +350,7 @@ static gboolean filter_data_remove_callback(struct filter_data *data,
 						struct filter_callback *cb)
 {
 	DBusConnection *connection;
+	struct filter_data *data_next;
 
 	data->callbacks = g_slist_remove(data->callbacks, cb);
 	data->processed = g_slist_remove(data->processed, cb);
@@ -376,12 +377,17 @@ static gboolean filter_data_remove_callback(struct filter_data *data,
 
 	connection = dbus_connection_ref(data->connection);
 	listeners = g_slist_remove(listeners, data);
+
+	/*
+	 * filter_data_free() may remove the latest data - we need to check
+	 * before it runs if it's our duty to remove the filter
+	 */
+	data_next = filter_data_find(connection, NULL, NULL, NULL, NULL, NULL,
+									NULL);
 	filter_data_free(data);
 
 	/* Remove filter if there are no listeners left for the connection */
-	data = filter_data_find(connection, NULL, NULL, NULL, NULL, NULL,
-					NULL);
-	if (data == NULL)
+	if (data_next == NULL)
 		dbus_connection_remove_filter(connection, message_filter,
 						NULL);
 
-- 
1.7.11


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-06-28  7:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-23 14:02 [PATCH BlueZ] gdbus: Fix removal of filter after last filter_data Lucas De Marchi
2012-06-25  8:51 ` Luiz Augusto von Dentz
2012-06-25 13:26   ` Lucas De Marchi
2012-06-25 15:14     ` Luiz Augusto von Dentz
2012-06-25 15:44       ` [PATCH BlueZ 1/3] " Lucas De Marchi
2012-06-25 15:44         ` [PATCH BlueZ 2/3] telephony-ofono: Fix listening for signals Lucas De Marchi
2012-06-25 15:44         ` [PATCH BlueZ 3/3] maemo6: mce: " Lucas De Marchi
2012-06-25 15:55           ` Luiz Augusto von Dentz
2012-06-25 15:56             ` Lucas De Marchi
2012-06-26  7:45         ` [PATCH BlueZ 1/3] gdbus: Fix removal of filter after last filter_data Luiz Augusto von Dentz
2012-06-28  7:39         ` Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox