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);