From 33ea56bf12562dbe03d4c2abd3b16d501d9c5c47 Mon Sep 17 00:00:00 2001 From: Florian Date: Thu, 16 Mar 2023 08:00:47 -0500 Subject: [PATCH] [BT] copy advertised device to avoid concurrent data access. (#1537) Co-authored-by: h2zero --- main/ZgatewayBT.ino | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index f9ebb99249..c4fe3e10e5 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -563,8 +563,10 @@ static int taskCore = 0; class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks { void onResult(BLEAdvertisedDevice* advertisedDevice) { - if (xQueueSend(BLEQueue, &advertisedDevice, 0) != pdTRUE) { + BLEAdvertisedDevice* ad = new BLEAdvertisedDevice(*advertisedDevice); + if (xQueueSend(BLEQueue, &ad, 0) != pdTRUE) { Log.error(F("BLEQueue full" CR)); + delete (ad); } } }; @@ -597,6 +599,7 @@ void procBLETask(void* pvParameters) { if (BTConfig.filterConnectable && device->connect) { Log.notice(F("Filtered connectable device" CR)); + delete (advertisedDevice); continue; } @@ -636,6 +639,7 @@ void procBLETask(void* pvParameters) { Log.trace(F("Filtered MAC device" CR)); } } + delete (advertisedDevice); } }