From 28457946df048e9e21c53c47dd3d31fad8494b37 Mon Sep 17 00:00:00 2001 From: Andrii Bilynskyi Date: Mon, 10 Apr 2023 15:08:18 +0300 Subject: [PATCH] [Telink] Fix NotifyAdvertisingStopped with Null node Since in file src/platform/Zephyr/BLEAdvertisingArbiter.cpp function InsertRequest obtains previous node using iteration via slist - condition (prev == nullptr) is only true if slist is empty. In that case NotifyAdvertisingStopped is always called with Null and no Null checker inside the function. As result crash. --- src/platform/Zephyr/BLEAdvertisingArbiter.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/platform/Zephyr/BLEAdvertisingArbiter.cpp b/src/platform/Zephyr/BLEAdvertisingArbiter.cpp index 29f55168f1c627..1e8ff7bb2e7501 100644 --- a/src/platform/Zephyr/BLEAdvertisingArbiter.cpp +++ b/src/platform/Zephyr/BLEAdvertisingArbiter.cpp @@ -90,7 +90,6 @@ CHIP_ERROR InsertRequest(Request & request) if (prev == nullptr) { - NotifyAdvertisingStopped(sys_slist_peek_head(&sRequests)); sys_slist_prepend(&sRequests, &request); } else @@ -110,6 +109,13 @@ CHIP_ERROR InsertRequest(Request & request) void CancelRequest(Request & request) { const bool isTopPriority = (sys_slist_peek_head(&sRequests) == &request); + + // If cancelled request was top-priority, stop the advertising. + if (isTopPriority) + { + NotifyAdvertisingStopped(sys_slist_peek_head(&sRequests)); + } + VerifyOrReturn(sys_slist_find_and_remove(&sRequests, &request)); // If cancelled request was top-priority, restart the advertising.