Skip to content

Commit 361b3da

Browse files
authored
Fix LockEventMutex referencing a disposed pointer (#2513) due to lack of error handling on create semaphore.
1 parent d95f848 commit 361b3da

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

targets/ESP32/_nanoCLR/nanoFramework.Device.Bluetooth/esp32_nimble.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,18 @@ void Device_ble_dispose()
474474
}
475475

476476
BLE_DEBUG_PRINTF("delete mutexs\n");
477-
vEventGroupDelete(ble_event_waitgroup);
478-
vSemaphoreDelete(ble_event_data.mutex);
477+
478+
if (ble_event_waitgroup)
479+
{
480+
vEventGroupDelete(ble_event_waitgroup);
481+
}
482+
if (ble_event_data.mutex)
483+
{
484+
vSemaphoreDelete(ble_event_data.mutex);
485+
}
486+
487+
ble_event_waitgroup = NULL;
488+
ble_event_data.mutex = NULL;
479489

480490
ble_initialized = false;
481491

@@ -507,6 +517,12 @@ bool DeviceBleInit()
507517
ble_event_waitgroup = xEventGroupCreate();
508518
ble_event_data.mutex = xSemaphoreCreateMutex();
509519

520+
if (!ble_event_waitgroup || !ble_event_data.mutex)
521+
{
522+
BLE_DEBUG_PRINTF("Ble Event Wait Group or mutex is null\n");
523+
return false;
524+
}
525+
510526
nimble_port_init();
511527

512528
// Initialize the NimBLE host configuration

0 commit comments

Comments
 (0)