fix(nimble) Free controller memory if init fails

This commit is contained in:
Rahul Tank
2024-05-08 09:55:12 +05:30
parent 5adfd2d3c4
commit fdc3526193
+18 -1
View File
@@ -181,6 +181,11 @@ nimble_port_init(void)
ret = esp_bt_controller_enable(ESP_BT_MODE_BLE);
if (ret != ESP_OK) {
// Deinit to free any memory the controller is using.
if(esp_bt_controller_deinit() != ESP_OK) {
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller deinit failed\n");
}
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller enable failed\n");
return ret;
}
@@ -188,7 +193,19 @@ nimble_port_init(void)
ret = esp_nimble_init();
if (ret != ESP_OK) {
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "nimble host init failed\n");
#if CONFIG_BT_CONTROLLER_ENABLED
// Disable and deinit controller to free memory
if(esp_bt_controller_disable() != ESP_OK) {
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller disable failed\n");
}
if(esp_bt_controller_deinit() != ESP_OK) {
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "controller deinit failed\n");
}
#endif
ESP_LOGE(NIMBLE_PORT_LOG_TAG, "nimble host init failed\n");
return ret;
}