summaryrefslogtreecommitdiff
path: root/gdbus/watch.c
diff options
context:
space:
mode:
Diffstat (limited to 'gdbus/watch.c')
-rw-r--r--gdbus/watch.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/gdbus/watch.c b/gdbus/watch.c
index 9e4f994..0f99f4f 100644
--- a/gdbus/watch.c
+++ b/gdbus/watch.c
@@ -281,6 +281,11 @@ static void filter_data_free(struct filter_data *data)
{
GSList *l;
+ /* Remove filter if there are no listeners left for the connection */
+ if (filter_data_find(data->connection) == NULL)
+ dbus_connection_remove_filter(data->connection, message_filter,
+ NULL);
+
for (l = data->callbacks; l != NULL; l = l->next)
g_free(l->data);
@@ -360,8 +365,6 @@ static void service_data_free(struct service_data *data)
static gboolean filter_data_remove_callback(struct filter_data *data,
struct filter_callback *cb)
{
- DBusConnection *connection;
-
data->callbacks = g_slist_remove(data->callbacks, cb);
data->processed = g_slist_remove(data->processed, cb);
@@ -385,16 +388,8 @@ static gboolean filter_data_remove_callback(struct filter_data *data,
if (data->registered && !remove_match(data))
return FALSE;
- connection = dbus_connection_ref(data->connection);
listeners = g_slist_remove(listeners, data);
-
- /* Remove filter if there are no listeners left for the connection */
- if (filter_data_find(connection) == NULL)
- dbus_connection_remove_filter(connection, message_filter,
- NULL);
-
filter_data_free(data);
- dbus_connection_unref(connection);
return TRUE;
}
@@ -524,6 +519,8 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
dbus_message_get_args(message, NULL, DBUS_TYPE_STRING, &arg, DBUS_TYPE_INVALID);
/* Sender is always the owner */
+ if (sender == NULL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
for (current = listeners; current != NULL; current = current->next) {
data = current->data;
@@ -563,6 +560,9 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
current);
}
+ if (delete_listener == NULL)
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+
for (current = delete_listener; current != NULL;
current = delete_listener->next) {
GSList *l = current->data;
@@ -581,11 +581,6 @@ static DBusHandlerResult message_filter(DBusConnection *connection,
g_slist_free(delete_listener);
- /* Remove filter if there are no listeners left for the connection */
- if (filter_data_find(connection) == NULL)
- dbus_connection_remove_filter(connection, message_filter,
- NULL);
-
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
@@ -593,12 +588,16 @@ static gboolean update_service(void *user_data)
{
struct service_data *data = user_data;
struct filter_callback *cb = data->callback;
+ DBusConnection *conn;
update_name_cache(data->name, data->owner);
+ conn = dbus_connection_ref(data->conn);
+ service_data_free(data);
+
if (cb->conn_func)
- cb->conn_func(data->conn, cb->user_data);
+ cb->conn_func(conn, cb->user_data);
- service_data_free(data);
+ dbus_connection_unref(conn);
return FALSE;
}
@@ -810,6 +809,4 @@ void g_dbus_remove_all_watches(DBusConnection *connection)
listeners = g_slist_remove(listeners, data);
filter_data_call_and_free(data);
}
-
- dbus_connection_remove_filter(connection, message_filter, NULL);
}