From 1cc3cf08c4934e3c4dc1413e11ac84ac53ea28cf Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Mon, 19 Aug 2024 16:32:27 -0400 Subject: [PATCH] hog-lib: Fix calling bt_uhid_destroy with invalid instance If the hog->uhid cannot be created then it is pointless to call bt_uhid_destroy as it will likely just produce bogus output as in: https://github.com/bluez/bluez/issues/529#issuecomment-2297350805 --- profiles/input/hog-lib.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/profiles/input/hog-lib.c b/profiles/input/hog-lib.c index 1b4aca074..729603702 100644 --- a/profiles/input/hog-lib.c +++ b/profiles/input/hog-lib.c @@ -830,14 +830,16 @@ static void uhid_destroy(struct bt_hog *hog, bool force) { int err; + if (!hog->uhid) + return; + + bt_uhid_unregister_all(hog->uhid); + err = bt_uhid_destroy(hog->uhid, force); if (err < 0) { error("bt_uhid_destroy: %s", strerror(-err)); return; } - - if (bt_uhid_created(hog->uhid)) - bt_uhid_unregister_all(hog->uhid); } static void set_report(struct uhid_event *ev, void *user_data) -- 2.47.3