From e6875504e98eba447c9f3cb22823943fa20b7f29 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Sun, 16 Apr 2023 10:27:19 +0200 Subject: [PATCH] ble_hs_stop.c: Prevent duplicate entries in ble_hs_stop_listeners. Under circumstances not fully clear sometimes duplicate list elements are added to the `list ble_hs_stop_listeners`. If that happens, the function `ble_hs_stop_done()` never terminates. This PR adds a check into `ble_hs_stop_register_listener()` if a to-be-added node/sublist already exist in the list and the it does not add this element. While this is anyhow a good test, it should not be needed in the MicroPython environment. --- nimble/host/src/ble_hs_stop.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/nimble/host/src/ble_hs_stop.c b/nimble/host/src/ble_hs_stop.c index b90d3ec6fc..ecc35aac5e 100644 --- a/nimble/host/src/ble_hs_stop.c +++ b/nimble/host/src/ble_hs_stop.c @@ -172,8 +172,17 @@ static void ble_hs_stop_register_listener(struct ble_hs_stop_listener *listener, ble_hs_stop_fn *fn, void *arg) { + struct ble_hs_stop_listener *node; BLE_HS_DBG_ASSERT(fn != NULL); + // Check, if the to-be-inserted list/node is already in the list + // If it is, do NOT insert it. + SLIST_FOREACH(node, &ble_hs_stop_listeners, link) { + if (listener == node) { + return; + } + } + listener->fn = fn; listener->arg = arg; SLIST_INSERT_HEAD(&ble_hs_stop_listeners, listener, link);