Skip to content

Commit 28c7a1e

Browse files
committed
Fix crash after empty REPL session
We were trying to reset bluetooth when it was off and then trying to raise an exception without the heap.
1 parent 90c6767 commit 28c7a1e

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

ports/nrf/common-hal/_bleio/Adapter.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,10 @@ void bleio_adapter_gc_collect(bleio_adapter_obj_t* adapter) {
723723

724724
void bleio_adapter_reset(bleio_adapter_obj_t* adapter) {
725725
common_hal_bleio_adapter_stop_scan(adapter);
726-
common_hal_bleio_adapter_stop_advertising(adapter);
726+
if (adapter->current_advertising_data != NULL) {
727+
common_hal_bleio_adapter_stop_advertising(adapter);
728+
}
729+
727730
adapter->connection_objs = NULL;
728731
for (size_t i = 0; i < BLEIO_TOTAL_CONNECTION_COUNT; i++) {
729732
bleio_connection_internal_t *connection = &bleio_connections[i];

ports/nrf/common-hal/_bleio/__init__.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,15 @@ void check_sec_status(uint8_t sec_status) {
8989

9090
// Turn off BLE on a reset or reload.
9191
void bleio_reset() {
92+
if (!common_hal_bleio_adapter_get_enabled(&common_hal_bleio_adapter_obj)) {
93+
return;
94+
}
9295
bleio_adapter_reset(&common_hal_bleio_adapter_obj);
9396
if (!vm_used_ble) {
9497
// No user-code BLE operations were done, so we can maintain the supervisor state.
9598
return;
9699
}
97-
if (common_hal_bleio_adapter_get_enabled(&common_hal_bleio_adapter_obj)) {
98-
common_hal_bleio_adapter_set_enabled(&common_hal_bleio_adapter_obj, false);
99-
}
100+
common_hal_bleio_adapter_set_enabled(&common_hal_bleio_adapter_obj, false);
100101
bonding_reset();
101102
supervisor_start_bluetooth();
102103
}

0 commit comments

Comments
 (0)