From df78ea46d5a2544a24a72c29e09e4cae9bdd5e71 Mon Sep 17 00:00:00 2001 From: Claudio Takahasi Date: Thu, 3 Apr 2014 16:46:51 -0300 Subject: [PATCH] gatt: Fix possibly lost block when bluetoothd exits This patch fixes a possibly lost memory related to GDBusClient and GDBusProxy objects when bluetoothd daemon exits and there is registered external service. ==1503== by 0x47ECFB: g_dbus_client_new (client.c:1232) ==1503== by 0x461EC7: register_service (gatt-dbus.c:510) --- src/gatt-dbus.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/gatt-dbus.c b/src/gatt-dbus.c index d3fd717f9..26437e7fd 100644 --- a/src/gatt-dbus.c +++ b/src/gatt-dbus.c @@ -96,6 +96,19 @@ static gboolean external_service_destroy(void *user_data) return FALSE; } +static void external_service_free(void *user_data) +{ + struct external_service *esvc = user_data; + + /* + * Set callback to NULL to avoid potential race condition + * when calling remove_service and GDBusClient unref. + */ + g_dbus_client_set_disconnect_watch(esvc->client, NULL, NULL); + + external_service_destroy(user_data); +} + static void remove_service(DBusConnection *conn, void *user_data) { struct external_service *esvc = user_data; @@ -634,6 +647,8 @@ void gatt_dbus_manager_unregister(void) g_hash_table_destroy(proxy_hash); proxy_hash = NULL; + g_slist_free_full(external_services, external_service_free); + g_dbus_unregister_interface(btd_get_dbus_connection(), "/org/bluez", GATT_MGR_IFACE); } -- 2.47.3