From 746ecbe5948a9b43ac2f6bf4f2fa67920dcc9dac Mon Sep 17 00:00:00 2001 From: Corentin Lecouvey Date: Mon, 15 Dec 2014 16:33:32 +0100 Subject: [PATCH] remove dbus matches when unregistering events While running TCT tests, the dbus match limit seems to be reached and then TCT application crashes. Change-Id: I15ec5493f1d8b6ad733ea5b852216b124ec5ec78 Signed-off-by: Corentin Lecouvey --- bt-api/bt-event-handler.c | 16 ++++++++++++++-- bt-api/include/bt-event-handler.h | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/bt-api/bt-event-handler.c b/bt-api/bt-event-handler.c index 3d87fde..acce5bd 100644 --- a/bt-api/bt-event-handler.c +++ b/bt-api/bt-event-handler.c @@ -1768,6 +1768,7 @@ int _bt_register_event(int event_type, void *event_cb, void *user_data) cb_data->event_type = event_type; cb_data->conn = connection_type; cb_data->func = event_func; + cb_data->match_rule = match; cb_data->cb = event_cb; cb_data->user_data = user_data; @@ -1788,8 +1789,6 @@ int _bt_register_event(int event_type, void *event_cb, void *user_data) goto fail; } - g_free(match); - event_list = g_slist_append(event_list, cb_data); return BLUETOOTH_ERROR_NONE; @@ -1807,6 +1806,8 @@ int _bt_unregister_event(int event_type) DBusConnection *connection_type; DBusHandleMessageFunction event_func; bt_event_info_t *cb_data; + char *match; + DBusError dbus_error; if (is_initialized == FALSE) { BT_ERR("Event is not registered"); @@ -1827,14 +1828,25 @@ int _bt_unregister_event(int event_type) connection_type = cb_data->conn; event_func = cb_data->func; + match = cb_data->match_rule; event_list = g_slist_remove(event_list, (void *)cb_data); retv_if(connection_type == NULL, BLUETOOTH_ERROR_INTERNAL); retv_if(event_func == NULL, BLUETOOTH_ERROR_INTERNAL); + dbus_error_init(&dbus_error); + + dbus_bus_remove_match (connection_type, match, &dbus_error); + + if (dbus_error_is_set(&dbus_error)) { + BT_ERR("Fail to remove match: %s\n", dbus_error.message); + dbus_error_free(&dbus_error); + } + dbus_connection_remove_filter(connection_type, event_func, (void *)cb_data); + g_free(match); return BLUETOOTH_ERROR_NONE; } diff --git a/bt-api/include/bt-event-handler.h b/bt-api/include/bt-event-handler.h index 307d2cc..cd3ea10 100644 --- a/bt-api/include/bt-event-handler.h +++ b/bt-api/include/bt-event-handler.h @@ -36,6 +36,7 @@ typedef struct { int event_type; DBusConnection *conn; DBusHandleMessageFunction func; + char *match_rule; void *cb; void *user_data; } bt_event_info_t; -- 2.7.4