From 29ff30b4c7627b96de2e87f853b7e198206ed94a Mon Sep 17 00:00:00 2001 From: "isha.pardikar@espressif.com" Date: Mon, 24 Apr 2023 17:35:16 +0530 Subject: [PATCH] wifi_prov_mgr: Fixed memory leak after bluetooth stack was stopping. --- components/protocomm/src/transports/protocomm_ble.c | 10 ++++++++++ components/protocomm/src/transports/protocomm_nimble.c | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/components/protocomm/src/transports/protocomm_ble.c b/components/protocomm/src/transports/protocomm_ble.c index 0d2fe1416d..a9e1f8d516 100644 --- a/components/protocomm/src/transports/protocomm_ble.c +++ b/components/protocomm/src/transports/protocomm_ble.c @@ -342,6 +342,15 @@ static void transport_simple_ble_connect(esp_gatts_cb_event_t event, esp_gatt_if { esp_err_t ret; ESP_LOGD(TAG, "Inside BLE connect w/ conn_id - %d", param->connect.conn_id); + +#ifdef CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV + /* Ignore BLE events received after protocomm layer is stopped */ + if (protoble_internal == NULL) { + ESP_LOGI(TAG,"Protocomm layer has already stopped"); + return; + } +#endif + if (protoble_internal->pc_ble->sec && protoble_internal->pc_ble->sec->new_transport_session) { ret = protoble_internal->pc_ble->sec->new_transport_session(protoble_internal->pc_ble->sec_inst, @@ -588,6 +597,7 @@ esp_err_t protocomm_ble_stop(protocomm_t *pc) if (ret) { ESP_LOGE(TAG, "BLE stop failed"); } + simple_ble_deinit(); #else #ifdef CONFIG_WIFI_PROV_DISCONNECT_AFTER_PROV /* Keep BT stack on, but terminate the connection after provisioning */ diff --git a/components/protocomm/src/transports/protocomm_nimble.c b/components/protocomm/src/transports/protocomm_nimble.c index cb22f71af7..973013cbcd 100644 --- a/components/protocomm/src/transports/protocomm_nimble.c +++ b/components/protocomm/src/transports/protocomm_nimble.c @@ -564,6 +564,15 @@ static void transport_simple_ble_connect(struct ble_gap_event *event, void *arg) { esp_err_t ret; ESP_LOGD(TAG, "Inside BLE connect w/ conn_id - %d", event->connect.conn_handle); + +#ifdef CONFIG_WIFI_PROV_KEEP_BLE_ON_AFTER_PROV + /* Ignore BLE events received after protocomm layer is stopped */ + if (protoble_internal == NULL) { + ESP_LOGI(TAG,"Protocomm layer has already stopped"); + return; + } +#endif + if (protoble_internal->pc_ble->sec && protoble_internal->pc_ble->sec->new_transport_session) { ret = @@ -971,6 +980,7 @@ esp_err_t protocomm_ble_stop(protocomm_t *pc) ESP_LOGE(TAG, "esp_nimble_hci_and_controller_deinit() failed with error: %d", ret); } } + free_gatt_ble_misc_memory(ble_cfg_p); #else #ifdef CONFIG_WIFI_PROV_DISCONNECT_AFTER_PROV /* Keep BT stack on, but terminate the connection after provisioning */